Hide one form element until another is selected Is there any way to disable the field 'model_article_nr' until 'model' is selected

this is what i have and as it is now i can select 'model_article_nr' before i have choosen a model which leads to wrong article nummer if i change model afterwords, because when no model is selected the first model is standard in my '$article_list[$curent_model]' and beeing displayed as options in 'model_article_number'

$model_list = array();
$article_list = get_model_article_list();

foreach($article_list as $key =&gt; $value) {
        if ( empty($curent_model) ) $curent_model = $key;
        $model_list[$key] = $key;
    }

$form['model'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Model'),
        '#title_display' =&gt; 'invisible',
        '#empty_option' =&gt; t('Select Model'),
        '#options' =&gt; $model_list,
        '#ajax' =&gt; array(
            'callback' =&gt; 'form_model_callback',
            'wrapper' =&gt; 'article-number-ajax-wrapper',
        ),
        '#prefix' =&gt; '&lt;div class="clearfix"&gt;&lt;/div&gt;&lt;div class="form-helper-container"&gt;',
        '#suffix' =&gt; '&lt;button type="button" class="btn tooltip-btn" data-toggle="modal" data-target="#model-help"&gt;&lt;span class="glyphicon glyphicon-question-sign"&gt;&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;',
    );

    $form['model_article_nr'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Article Number'),
        '#title_display' =&gt; 'invisible',
        '#attributes' =&gt; array('placeholder' =&gt; t('Article Number'), 'class' =&gt; array('space-bottom')),
        '#empty_option' =&gt; t('Select Article Number'),
        '#validated' =&gt; TRUE,
        '#options' =&gt; $article_list[$curent_model],
        '#prefix' =&gt; "&lt;div id='article-number-ajax-wrapper'&gt;",
        '#suffix' =&gt; "&lt;/div&gt;",
    );


And my callback

function form_model_callback($form, &amp;$form_state) {
    return $form['model_article_nr'];
}
As @leymannx stated you can achieve this using #states. Here is a simple example:



 $form['show_textbox'] = array(
  '#type' =&gt; 'checkbox',
  '#title' =&gt; t('Show text Box 1'),
        '#attributes' =&gt; [
        'id' =&gt; 'show_textbox',
        'name' =&gt; 'field_show_textbox',
      ],
);

    $form['text_box1'] = [
      '#type' =&gt; 'textfield',
      '#size' =&gt; '60',
      '#placeholder' =&gt; 'Enter Name',
      '#attributes' =&gt; [
        'id' =&gt; 'text_box1',
        'autocorrect' =&gt; 'none',
        'class' =&gt; 'text_box1',
        'autocapitalize' =&gt; 'none',
        'spellcheck' =&gt; 'false',
      ],
      '#states' =&gt; [
        //show this textfield only if the radio button 'show_textbox1' is selected
        'visible' =&gt; [
                ':input[name="field_show_textbox"]' =&gt; array('checked' =&gt; TRUE),
        ],
      ],
    ];



You can always change the condition.