Drupal Form API uses `#states` for creating form elements that change state (show, hide, enable, disable, etc). These states can be toggled based on the value(s) of other form elements to create dynamic forms.

learn more… | top users | synonyms

0
votes
0answers
14 views

Enable for submit button only when Date is selected (disable if date empty)

I have a form which has a Date field with end and start date. I've created following states properties which seem to have some effect since submit button has new class form-button-disabled. Though ...
0
votes
0answers
25 views

how do i set original value after $form_state->setRebuild(TRUE);

i have form, with dynamic fields that can be added and removed from button using ajax submit/callbacks. the problem that i encounter is: every-time i add new field, the 'add button' will submit with ...
0
votes
0answers
21 views

#states hide by radio won't work

The problem is all in the title. So here is my code (i cut some part to make it more visible) : Constructor : public function __construct() { $user = \Drupal\user\Entity\User::load(\Drupal::...
0
votes
1answer
32 views

Conditional field on checkbox is not woking

If the checkbox is checked then it will show the textbox else not, for this purpose i've written this code. But it is not working, even the textfield is not showing.what do i need to change in this ...
0
votes
1answer
16 views

Setting #states property for a field_collection item added with the add_more button

This is a D8 question as the solution in Using #states with field collection doesn't work for D8. Here are the solutions I have tried, but none of them was working: 1- Adding an after build function ...
0
votes
2answers
55 views

How to add 'not equal' condition in form #states

In my form, there are 3 selection list A, B and C. I wanna show or hide C based on values of A and B selected. C should be shown if A's value = 'all and B's value != 'all' How to set the #state ...
0
votes
1answer
56 views

Show and hide form element based on values of other form elements

$form['bookpage'] should be hidden at first. Then should be shown based on user selected value in $form['student']. But somehow, before user selects anything, upon loading the option list, it ...
1
vote
0answers
26 views

How to use #states with a container element?

I come from read this Using the Drupal 7 Form API states system to create conditions between form elements and I'm able to use the #states with an input element like the title (textfield element), the ...
0
votes
0answers
12 views

state field dependent by country fileds

I have a content type (candidate_profile) fields (First Name, Last Name,Years into Career(since college),Years in New Business Role and Location/Region). In location field( field_type = select-box) ...
0
votes
0answers
11 views

#states and node content type: how to add?

I need to add a #states to a group into a node content type form (I will use hook_form_alter). I have tried to see if via "field_dependecies" (and this module is active on that site) I could do this, ...
1
vote
2answers
47 views

field_group #states does not working with using hook_field_group_build_pre_render_alter()

I am trying to use #states on field_group at node add form. From the search results I can find a couple of links which shows that hook_field_group_build_pre_render_alter() can make the magic but ...
1
vote
1answer
37 views

Drupal form, check if select field has been used with states

I have a form where I'd like to hide a fieldset until the user has used a select (which option doesn't matter). So far I've the following code: $form['location'] = array( '#type' => 'select', ...
1
vote
1answer
30 views

Form states with “and” and “or” conditions

Using form API in D7, I need to use from states to setup a visible input with this condition : field1 = value A AND (field2 = value B OR value C OR value D) Something like this, but this example ...
1
vote
2answers
38 views

How to simulate radio button functionality within a form

I have a form which has 3 radio buttons, each providing a fieldset. o Choice 1 Fieldset of options v o Choice 2 Fieldset of options v o Choice 3 Fieldset of options v In order to achieve this,...
0
votes
1answer
74 views

8 - form #states greater than x

How do I use #states to show an field if the value of another field is greater than one of my variables? The code below is for =$chkval $chkval = 4; // This would be set by a database query '#...
0
votes
0answers
82 views

How to show empty fields labels only if conditional state is "visible'

I use the Conditional Fields module to show some fields only if other fields matches conditions. I use the Empty Fields Module to show a custom text when a field is empty (for example : "unknown") ...
0
votes
1answer
18 views

How do I make a block appear in a panels display based on the state of a field

I have a field that is a single on/off checkbox. Whenever it has been selected it outputs a key of 1 into the panel display, if it hasn't it outputs a 0. I want it to output custom html for a link to ...
1
vote
0answers
55 views

Why is Form '#states' not working?

I've used the Address Field module in my registration form with other fields. I've one select field to display some numbers and one textfield to get some numbers from users. This textfield should be ...
0
votes
1answer
27 views

How can I write an input selector for the states API?

I'm trying to use the #states API but my input selector isn't being picked up. This is the code I've added to hook_form_alter() in a custom module: case 'my_form': $form['revision_information'...
0
votes
0answers
71 views

Conditional Fields Based on an element in a fieldset using states

I have a select form element: $form['myid_template'] = array( '#type' => 'fieldset', '#title' => t('Select Template'), ); $form['myid_template']['template_options'] = array( '#...
0
votes
0answers
105 views

How to force form_state['input'] to form_state['values']

I have a custom form that uses AJAX to add new fieldsets internal users can specify a default set of artists, e.g. 4, and send this to a record label/management etc. the rep can come to the form, ...
0
votes
2answers
25 views

State of form element based on global config

I have a form_alter that adds some settings on a content type. How can I make one of these elements hidden (and cleared?) based on the value of a global config (set with variable_get)? I found the ...
1
vote
0answers
38 views

Form always visible even when radiobutton value is changed (form api)

i'm having an issue with the property #states visible on a form. I want to hide it when form mercuriale's value is 1. $isMercuriale = db_query('SELECT isMercuriale FROM groupes_catalogues WHERE id = ...
1
vote
1answer
83 views

Forms API #states with multiple radios

I've got one radios element: $form['trip_radios'] = array( '#type' => 'radios', '#options' => array( 'new' => t('Create a new trip'), 'existing' => t('Use an existing trip'), ...
5
votes
3answers
830 views

Use drupal #states to check a radio

I would like to translate some jquery .change functionality to use #states in the form api. var radio1 = jQuery('input:radio[name=radio_1]'); var radio2 = jQuery('input:radio[name=radio_2]'); ...
0
votes
0answers
77 views

It is possible to use FAPI #states on hidden elements?

I want to enable a submit button based of a hidden input value. Right now i have this but it does not seem to work. $states = array(); $dependencies = array(); foreach ($w_exercise-&...
0
votes
1answer
26 views

What is the recommendation for mapping state?

The configuration in D8 is nicely mapped in config schema file so any developer knows what configuration changes can be made. But what about state? Is there a recommended way to map state? Or is it ...
1
vote
0answers
25 views

#states not detecting a change to form via ajax_command_invoke

I have a form. On an elements I have an ajax call back. In the callback I use the commands[] to update some elements on the screen. One of the elements I update is used by another form element using ...
1
vote
1answer
96 views

using hook_form_FORM_ID_alter with #states

I am trying to use checkboxes to display inline entity form elements only when the boxes are checked. However, my code doesn't seem to be working. It will hide the element, but when I toggle the ...
1
vote
1answer
89 views

Using #states API with an image field as a control field

On a form, is it possible to use #states to hide/show a field based on whether or not an image field has been filled in? More specifically, I'd like to get this node form: to only show the "Show ...
5
votes
2answers
1k views

How to get Form API #states selected value onchange?

When I'm using #states to set the visibility of a form field I'm checking an input element for its value. Is there then any way to grab the selected value the moment it's selected? In the working ...
0
votes
1answer
305 views

Using #states to disable a field collection field

I am trying to disable a date field's second value, inside a field collection, but it isn't working. My hook_form_alter has this: $form['field_certification']['und'][0]['field_validity']['und'][0][...
1
vote
0answers
64 views

How can i use the Drupal form API states to make my field value depend on another field value?

Basically what I'm trying to do is to change the #autocomplete_path for the author field in the node/add. The value of the #autocomplete_path will be dependent on the value of another field (a select ...
1
vote
2answers
490 views

Undesired toggle effect with #states and checkboxes

I'm working on a patch for the Login Disable module, and on the settings page, I want to have two mutually exclusive options so that when one is checked, the other is unchecked. Using the FAPI #states ...
1
vote
0answers
61 views

#states and language in selector - best practice

I am having trouble understanding when to use the language of the field in the selector when using #states. I have a content type of post. It has: a term reference post_type that has terms such as ...
0
votes
1answer
189 views

How to save a form inputs in database and retrieve it from database with out form submision

hi can i store form inputs in database and retrieve it from database with validation I search many sites but neither any documentation or example or any thing i found for drupal7 . I didn't ...
0
votes
1answer
139 views

Drupal hide form items completely with states

I try to hide a whole date/image/taxonomy block on my node form dependent on a checkbox. If use the following for my title field it works perfectly. The title field is hidden/visible dependant on the ...
4
votes
3answers
344 views

#states does not hide #suffix in a form

I am new to Drupal, so please be fair with me :) I am trying to create a custom form using FAPI. The code is as follows : $form['format_document'] = array( '#type' => 'radios', '#options' =&...
0
votes
3answers
793 views

Field Group Conditional State does not work after upgrade

After recent upgrade of fieldgroup module, the conditional state visibility for field group does not work now. Please find the previous code that used to work: function ...
2
votes
1answer
569 views

Form API #states with #default_value?

I have a form which has a select with a #default_value which get's set when the user has errors/has filled out the form. Then I have two fields with a #states that show them when the select has a ...
1
vote
1answer
180 views

Module has conditional Checkboxes, need to remove value

I am building a module that will have a bunch of checkboxes to enable the addition of metatags like HandheldFriendly, MobileOptimized, etc. I want to have the first checkbox only displayed. Upon ...
3
votes
1answer
2k views

When using hook_form_alter to modify a content type's node add / edit form, where do I put the #states property?

This is actually a compound question. All in all the question is: When using hook_form_alter to modify an existing content type's node add / edit form, where do I put the #states property, and, ...
2
votes
2answers
921 views

Using #states with field collection

I'm trying to use #states in a unlimited field collection (using the field collection module). I'm adding this functionality to a node add form so am altering form elements using hook_form_alter. I ...
4
votes
2answers
463 views

#states with effects (fade, slide)

I'm using the form api #states feature to show and hide fields based on the value of other inputs. This is working great however I would like to have the option to fade or slide the inputs as they ...
3
votes
3answers
756 views

FAPI #states for multiple selections.

I've used the FAPI #states system before to show/hide conditional fields. It's great. However, when I am trying to show a field based on another field's value, I'm running into a problem. The ...
1
vote
1answer
300 views

Drupal 7 #states on exposed filter form

I have a #states on the exposed filter form as follow: If field_a == 'b' then field_b show, field_c hidden; else if field_a == 'c' then field_c show, field_b hidden; All fields here are Select ...
0
votes
1answer
86 views

Form States conflict

I've two forms in a page, one of the field name is same in both forms. <form id="form1"> <div class="div1"> <select id="field_a" name="field_a_name"> ... </select> ...
0
votes
1answer
114 views

How do I create a text field in registration that only shows up if a checkbox is checked?

I am making a registration process in which there needs to be a text field that only appears if a checkbox is "on". I would think "parent" fields would do this, but whenever I click the "parent" ...
0
votes
1answer
96 views

#states attribute of FORM API?

Currently I am using states attribute in my form to show/hide a drodown having days as its value on selecting a parent dropdown value. My working scenerio is that I want to show a dropdown having 31 ...
0
votes
0answers
234 views

Can not get checkbox's to be mutually exclusive with simple form

I want 2 checkbox's that are mutually exclusive. In the example below when you click on one it will work for like one cycle then working as they will both become selected. Is this not possible? What ...