forms - yii2 validate empty dropdownlist, checkbox -
i have fields required in model , dropdownlist on form.
if try submit form without selecting no validation error occurs on view way textinput would.
model
[['name', 'survey_type','country_id'], 'required', 'isempty' => function ($value) { return empty($value); } ],
display empty red validation
<?= $form->field($model, 'name')->textinput(['maxlength' => 255]) ?>
does not display validation
<?= $form->field($model, 'survey_type')->dropdownlist([$surveytypelist],['prompt'=>'select survey type','id'=>'survey_type_dropdown']) ?>
this because overrided id
drop-down list:
'id' => 'survey_type_dropdown'
you shouldn't if want client validation working field.
ids generated automatically , used in javascript related activeform
.
remove , should fine:
<?= $form->field($model, 'survey_type')->dropdownlist([$surveytypelist],['prompt' => 'select survey type']) ?>
if want element in javascript, use auto generated id or assign custom class.
Comments
Post a Comment