limit validation button on visible state textfield? Suppose I had a selectbox with 2 options. One option enabling the visible state of one field, while the other disables that state and makes a different text field visible.

If I had a button that has limit_validation_errors, how would one go about validating only the field whose state is visible?

Currently my setup looks like the following:

$form['unit'] = array(
  '#type' =&gt; 'select',
  '#options' =&gt; array(
    0 =&gt; '€',
    1 =&gt; '%',
  ),
  '#default_value' =&gt; 0,
);


$form['price-percentage-field'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Price'),
  '#description' =&gt; t('Set the percentage discount price for this volume set'),
  '#size' =&gt; 10,
  '#element_validate' =&gt; array('price_percentage_validate'),
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="unit"]' =&gt; array('value' =&gt; 1),
    ),
  ),
);

$form['price-field'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Price'),
  '#description' =&gt; t('Set the price for this volume set'),
  '#size' =&gt; 10,
  '#element_validate' =&gt; array('price_validate'),
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="unit"]' =&gt; array('value' =&gt; 0),
    ),
  ),
);

$form['add'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Add'),
  '#name' =&gt; 'add_row',
  '#limit_validation_errors' =&gt; array(
    array('price-field'),
    array('price-percentage-field'),
  ),
  '#submit' =&gt; array('add_volume_standard'),
  '#ajax' =&gt; array(
    'callback' =&gt; 'add_volume_standard_ajax_callback',
    'wrapper' =&gt; 'error-placeholder', //&lt;- this here is for my custom error-placeholder that will contain the form_errors nicely in a div using a few ajax_commands and form_states
    'method' =&gt; 'append',
    'effect' =&gt; 'fade',
  ),
  '#title' =&gt; t('Click this button to add a standard volume price'),
);


When using this code, both fields will always be validated. While I want to only validate the visible field. How can I do this?

Also, a validation function is not my preferable approach. I have my reasons.
I would personally prefer a form-validation-function, which seems for me the ideal solution...
But since you're using custom validators, you can check the value of your unit-field in there:  

The second argument in your custom element-validation-function is the form_state-object, with that you have access all form-values. (eg. $form_state['values']['unit'])
Check the value of the unit-field in both validation-functions, depending of it's state do or skip the validation.

Example:

   function price_percentage_validate($element, &amp;$form_state, $form) {
        if ($form_state['values']['unit']&gt;0) {
            /* your validation code */
        }
    }
   function price_validate($element, &amp;$form_state, $form) {
        if ($form_state['values']['unit']&lt;1) {
            /* your validation code */
        }
    }