By SBOS on
I'm implementing the ajax "add more" functionality to a Drupal form. Basically, the user can enter a variable number of records into the form. So, there's an 'add more' button which when click is supposed to show an additional row in the form. I've got this working. The problem is that when I set a field in the form to be required, And the user has left it blank, the new row doesn't appear. Rather validation errors appear. I want the validation, of course, but I don't want it firing on the ajax callback. I've searched throughout and found nothing. How do I disable this validation that runs on an AJAX callback?
Comments
limit_validation_errors()
I think you can use limit_validation_errors().
Thanks worked like a charm
Refer this https://api.drupal.org/api/drupal/includes%21form.inc/function/form_set_...
adding #limit_validation_errors will not validate the form and discard the values
Thanks for your section code
It worked for me, thanks you
Just don't forget that by
Just don't forget that by setting
'#limit_validation_errors' => array(),your$form_state['values']are not going to be populated anymore.limit_validation_errors
Hi tce,
Thanks for this hint, it's working perfect. You saved my time.
Didn't work on radios
I have a radio with an ajax callback that displays some fields according to the selected option but the fields are getting validated on the callback, any ideas?
As explained in the
As explained in the documentation, this only applies to button, image, image_button and submit.
https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...