我在弹出模式中使用wbraganca动态表单。在此我需要根据单选按钮选择显示和验证字段。所以我在onchange事件中调用javascript函数。
<?= $form->field($model, "[{$i}]option")->dropDownList(['month'=>'Month','year'=>'Year'],["class"=>"custom-radio-inline","onChange"=>"changeFields($(this))"])->label(false);?>
我正在尝试使用下面的javascript获取检查值。它只使用第一组字段,如果用户添加另一个表单,它总是将值返回为1。
function changeFields(item)
{
var id = "#"+item.attr("id")+" input[type=radio]:checked";
var val = $(id).val()
console.log(val);
}
在这个我不知道的地方,请帮助任何人,我想根据这个单选按钮选择显示和隐藏字段,并根据此选择进行验证。 !重要这是我想要的每一种形式。
答案 0 :(得分:0)
在规则中使用whenClient。
[['myAtt'], 'required', 'whenClient' => new JsExpression("
function (attribute, value) {
console.log(attribute, value);
}
")]