DataPicker小部件:
<?= $form->field($model, 'dateSale')->textInput()->widget(DatePicker::classname(), [
'name' => 'dp_4',
'type' => DatePicker::TYPE_COMPONENT_PREPEND,
'disabled' => true
]) ?>
SwitchInput小部件:
<?= $form->field($model, 'status')->textInput()->widget(SwitchInput::classname(), [
'name' => 'status_11',
'pluginEvents' => [
'switchChange.bootstrapSwitch' => 'function(event, state) {
if (state == 0){
$("#vehicle-datesale").dp4("disabled", "false");
}
else {
$("#vehicle-datesale").dp4("disabled", "true");
}
}',
]
]) ?>
为什么不进行上述工作,我该怎么做?
答案 0 :(得分:1)
您需要更改SwitchInput
小部件中的代码。
use yii\helpers\Html;
<?= $form->field($model, 'status')->textInput()->widget(SwitchInput::classname(), [
'name' => 'status_11',
'pluginEvents' => [
'switchChange.bootstrapSwitch' => 'function(event, state) {
if (state == 0 || state == false){
$("#'.Html::getInputId($model, 'dateSale').'").attr("disabled", "false");
}
else {
$("#'.Html::getInputId($model, 'dateSale').'").attr("disabled", "true");
}
}',
]
]) ?>
答案 1 :(得分:0)
你的代码正在运作;只有改变:
if (state == 0 || state == false){
$("#'.Html::getInputId($model, 'dateSale').'").attr("disabled", "false");
}
else {
$("#'.Html::getInputId($model, 'dateSale').'").attr("disabled", "true");
}
通过
if (state == 0 || state == false){
$("#'.Html::getInputId($model, 'dateSale').'").attr("disabled", false);
}
else {
$("#'.Html::getInputId($model, 'dateSale').'").attr("disabled", true);
}