1

I would like to not validate fields if I submit button with ajax callback. Currently, on every button click it displays validation errors of another fields. The button doesn't submit the form, it does some another action (add more fields).

2

You need to set limit_validation_errors to an empty array for it to ignore the rest of the fields in the form. Here's an example:

  $form['a_field'] = array(
    '#type' => 'button',
    '#limit_validation_errors' => array(),
    '#value' => t('Click here'),
    '#name' => 'a_field',
    '#submit' => array('my_submit_function'),
    '#ajax' => array(
      'callback' => 'my_function',
      'wrapper' => 'my_wrapper',
    ),
  );

Not the answer you're looking for? Browse other questions tagged or ask your own question.