Very strange behavior. I have drupal form with two fields. One is company select and other is user select. When company is selected onchange is triggered and users are loaded in other field based on what company ID is. That is ok. Also below that form there are some fields that are locked until user is changed. I lock them with: check at beginning if ID is > 0 ant then show those fields (user IDS are > 0).
First field: 'onchange' =>'form.submit("proj")', $uid= -1, I set uid to -1 to lock fields again cause company is changed. But this is wired part:
When select company and then select user everything is ok. Below fields are unlocked. But when I change company again fields are not locked so $uid is not -1 (users are loaded ok!). But when I change company second time then fields are locked, $uid is -1 and everything is fine.
So problem is that my code works when I change company filed twice.
Part of code:
$form['proj'] = array(
'#type' => 'select',
'#required' => FALSE,
'#default_value' => $co_id,
'#title' => 'Firma',
'#options' => $options_proj,
'#attributes' => array(
'onchange' =>'form.submit("proj")', $uid= -1,
),
);
$form['mitarbeiter'] = array(
'#type' => 'select',
'#required' => FALSE,
'#default_value' => $temp,
'#title' => 'Mitarbeiter',
'#options' => $options_mitarbeiter,
'#attributes' => array(
'onchange' => 'form.submit("mitarbeiter")',
),
);Mitarbeiter is worker and firma is company
Comments
Examples module
The examples module has an example of dependent drop downs you could use:
http://drupal.org/project/examples
I think that would be a cleaner way to go about what you are trying to accomplish.
Cheers
Tom
Bristol based Drupal web design
BlackLabel Web Design
demos
Is there live demos for this examples? Maybe I could use field_example or form_example.
Check for 'ajax_example' from
Check for 'ajax_example' from below listed module. You can use the selected value of form element(company and user)to render, disable and enable other form elements.
http://drupal.org/project/examples
Tushar Bodake
other form elements
Yes, you can do that, but there is more than one form on the page. Four of them. I don't know if you can control behavior of one form from another.
Anyway, my boss says that is god this way so I will leave it like that.
OK Not sure about you
OK
Not sure about you implementation and requirements..
if the forms are depends on some form elements of different form and they are having common submit, then can we have all field in same form under different fieldset instead of having different forms. So we can update the respective form fieldset based on input.
OR you can have multistep form, where each form display at different step. And you can build the forms based on previous from elements value. Again multi step form can work with ajax(without page refresh).
Check for Ctool multistep wizard.
Thanks,
Tushar Bodake
Set up the module
If you install the module and enable the example you want to see it will then be a live example on your site.
Cheers
Tom
Bristol based Drupal web design
BlackLabel Web Design