Hi,
I think there is a serious limitation (or bug, or maybe a misunderstanding) with a FAPI preprocess function and ajax calls.
I see it when i try to make a very simple form (one text field, on submit button) and grouping them with #input_group_button
special key on field.
In _bootstrap_process_element()
function, we can see
// Automatically inject the nearest button found after this element if
// #input_group_button exists.
if (!empty($element['#input_group_button'])) {
...
}
That's a really great "helper" than can make input grouping append (see example http://getbootstrap.com/components/#input-groups-buttons).
With that, I can do that
$form['input_text'] = array(
'#title' => 'label',
'#type' => 'textfield',
'#size' => 15,
'#required' => TRUE,
'#attributes' => array(
'class' => array(
'col-xs'
),
),
'#input_group_button' => true,
);
$form["submit"] = array(
"#type" => "submit",
'#value' => t('Search'),
'#attributes' => array(
'class' => array(
'btn-blue'
),
),
"#ajax" => array(
"callback" => "_myformcallback_callback",
),
);
But with that, Drupal ajax API was not called.
So I add #ajax
to my text input
$form['input_text'] = array(
// ...
'#input_group_button' => true,
"#ajax" => array(
"callback" => "_myformcallback_callback",
),
);
With that ajax (_myformcallback_callback
) is called, when clicking on submit, or when pressing enter key in text input.
Nice but... The validation function IS called but errors are not "returned"
function myform_form_validate($form, &$form_state) {
form_set_error('input_text', 'Error test');
return $form_state;
}
At the consequence inside _myformcallback_callback
function, form_get_errors();
remains empty and code continue to run as if the was no validation function (or no error).
If I comment #input_group_button
all run fine (with validation) but output is not as desired (no grouping)
That's why I think it's a bootstrap bug. I know I can use preprocess or alter hook to get the desired output but this #input_group_button
key is a good helper to do that !
Thanks for helping, and sorry for my bad English
Comments
Comment #1
rroblik CreditAttribution: rroblik commentedComment #2
markhalliwellPretty sure this is no longer an issue. There was a lot of work done on this prior to the 7.x-3.1 release.