By turtletrail on
I have a text field, filling which should update several fields with the database values:
$form['evanr'] = array(
'#type' => 'textfield',
'#required' => TRUE,
...
'#ajax' => array(
'callback' => 'ajax_check_evaopgave',
'wrapper' => 'replace_sfp',
),
);
at the same time I have the field that is currently bonded to be updated:
$form['sfp'] = array(
'#type' => 'select',
'#options' => drupal_map_assoc(
...
),
'#prefix' => '<div id="replace_sfp">',
'#suffix' => '</div>',
'#value' => (get_sfp_value($form_state['values']['evanr'])),
);
and the supplier methods:
function ajax_check_evaopgave($form, $form_state) {
return $form['sfp'];
}
function get_sfp_value($evanr){
... //return value from database
}
The problem is that I need to update more than one field, when evanr field is filled.
How to attach multiple ajax callback to the same field?
Thanks in advance
Comments
Only one
You don't need attach multiple ajax callback to the same field, in only one callback you can update many fields but inside the same wrapper.
See http://drupal.org/project/examples
helped
thanks, I used this idea and it helped.
However, the examples you gave are not really explaining this concept,
but I also found this description, which is more explanatory in my opinion:
from AJAX Forms in Drupal 7, which basically extends your idea.
Thanks to you too
Thanks to you too.
new problem faced
I am having troubles with a new thing, but the root is the same - drupal's ajax functionality.
I discovered, that the problem comes from ajax '#path' attribute.
if it is set, ajax functionality is not doing its job - updating fields:
If it is not set, ajax functionality is working just fine:
but on form submit, i'm offered to save json file, and the form is not submitted.
Any help appreciated
solution found
the solution was simple it is just adding $form['#action'] with right url.
seems like ajax is changing the page url, which is hidden.
That is why submit didn't work unless i explicitly specified the action url.
Possible
It's possible to update two different element, even if they are on different part of the site. On this way it worked at me:
This is worked for me
This is worked for me
Thanks for sharing. This
Thanks for sharing. This saved a ton.
Best Regards,
Tajinder Singh Namdhari
https://TajinderSinghNamdhari.com
Its not working for me
I have two forms. one is main and second one is in the popUp. I want that the data of second form will appear in the first one on the submit button the second form. I am using variable_set and variable_get for keeping the data. The main page is showing my data on refreshing it. But i want to update it as soon as submit button is click on the second form.
Code for first Form..........
Here is the second form
here is the callback function
$commands = array();
$commands[] = ajax_command_replace('#table_id', drupal_render($form['table']));
$form_state['ajax_commands'][] = ctools_modal_command_dismiss();
return array('#type' => 'ajax', '#commands' => $commands);