简体   繁体   English

如果我的表单中的特定下拉列表为空,如何禁用按钮(以及其中的 href)? (Yii2)

[英]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.我一直在玩 javascript 多年,但似乎没有什么想要工作。

Well I believe you have to use a JS solution here.好吧,我相信您必须在这里使用 JS 解决方案。

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.您已经在 SelectBox 上有了“onChange”处理程序,所以我相信getProjects() function 是您可以处理这种情况的地方。

Have you tried something like this?你有没有尝试过这样的事情? https://jsfiddle.net/aj2xesy4/ https://jsfiddle.net/aj2xesy4/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM