Rachel Fitz
Rachel Fitz

Reputation: 55

How to disable button (and a href within it) if a particular dropdown in my form is empty? (Yii2)

I have this form with this particular field in it;

<?= $form->field($model, 't_client_company_id')->dropDownList(ArrayHelper::map(Time::getClients(), 'id', 'name'), array('prompt' => Yii::t('time', '(Select a Client)'), 'onchange' => "js:getProjects();")) ?>

I also have this button which i want to enable ONLY if this dropdown field is not empty; hence if a selection has been made. Please note that this button is NOT a submit button.

<?= Html::a(Yii::t('time', 'Create Notification'), ['#'], ['class'=>'btn btn-warning']) ?>

I have been playing around with javascript for ages but nothing seems to want to work.

Upvotes: 0

Views: 78

Answers (1)

Jiri Semmler
Jiri Semmler

Reputation: 421

Well I believe you have to use a JS solution here.

You already have the 'onChange' handler on the SelectBox, so I believe that the getProjects() function is the place where you can handle this scenario.

Have you tried something like this? https://jsfiddle.net/aj2xesy4/

Upvotes: 2

Related Questions