0

Helloo ! I am using the D7 reference option limit module. I have two fields "primary" and "secondary" and I managed to reduce the choices of secondary based on the value of primary using this module. Both of them are required field in the user registration form.

I have a small question, when I set no value for primary, I get for the secondary field: No options are available for the current form values. Try selecting different values for the following fields: Primary. This is the good behaviour that I want but I want to hide secondary when no value is set for primary instead of displaying this message..

Is that possible? In other words I want to keep secondary hidden until primary has a value.

0

have you try any alter functions to implement ?

if you can try with alter then try #states in hook_form_alter() to hide field, if primary field default value is empty/null.

here is e.g

/**
 * @param type $form
 * @param type $form_state
 * @param type $form_id
 * Implements hook_form_alter()
 */
function hook_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'form_id') {
    // Hide secondary field.
    if (isset($form['secondary_field'])) {
      $form['secondary_field']['#states'] = [
        'visible' => array(
          'input[name="primary_field"]' => array('!value' => ''),
        ),
      ];
    }
  }
}

'input[name="primary_field"]' => array('!value' => ''), change this as per need i.e if its select list then 'select[name="primary_field"]' => array('!value' => ''), etc.

hope this will solve your issue.

1
  • Thank you very muchh – Jasmin Nov 12 '20 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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