[英]Jquery to disable previous radio buttons in Yii2
<?= $form->field($model, 'status')->radioList(array('1'=>'Approved','2'=>'Digital','3'=>'CDP','4'=>'Print','5'=>'Other Process','6'=>'Packing','7'=>'Dispatch',)); ?>
I'm trying to implement status update form. 我正在尝试实施状态更新表格。 I want to know how can I disable previous radio buttons.
我想知道如何禁用以前的单选按钮。
eg- If current status is CDP then Status "Approved" and "Digital" should be disable. 例如-如果当前状态为CDP,则应禁用状态“已批准”和“数字”。
how to write java script for this, im implementing in Yii2 Framework. 如何为此编写Java脚本,即时在Yii2 Framework中实现。
Try to listen if someone choose a radio button. 如果有人选择单选按钮,请尝试听。 Than '.disable' on every button with '.each' until you reached the key.
在每个按键上都使用“ .each”而不是“ .disable”,直到找到按键为止。
edit: i hate to write it blind but try this: 编辑:我不喜欢盲目的写,但是尝试这个:
$('#radioButtons').on('change', function(){
var val = this.value;
$.each(arrayname, function( index, value ){
if(index < val){
value.disable();
}else{
value.enable();
}
});
});
if the selected value is smaller, it will be disable, otherwise it will be anabled. 如果所选值较小,则将其禁用,否则将启用。 but if you do it this way you can´t change your choice to a button above ?
但是,如果您采用这种方式,则无法将选择更改为上方的按钮? is this really what you want ?
这真的是您想要的吗?
Since your option will already be set you can use Yii2 to do this. 由于您的选项已被设置,因此您可以使用Yii2进行此操作。 You will need to manually set the input property "item" to do this.
您将需要手动设置输入属性“ item”以执行此操作。
<?=$form->field($model, 'status')->radioList(['1' => 'Approved', '2' => 'Digital', '3' => 'CDP', '4' => 'Print', '5' => 'Other Process', '6' => 'Packing', '7' => 'Dispatch'], ['item' => function($index, $label, $name, $checked, $value) {$checked = $checked == 1 ? 'checked=""' : 'disabled=""';echo "<label><input tabindex='{$index}' type='radio' {$checked}'name='{$name}'value='{$value}'> {$label}</label>";}]);?>
The above will leave the selected one checked and disable the others using the HTML options "checked" and "disabled" respectively. 上面的代码将使选中的一个保持选中状态,并分别使用HTML选项“ checked”和“ disabled”禁用其他选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.