我正在构建Yii2表单,并为用户体验设置了客户端验证以确认文本长度。 我希望用户仍然能够提交表格,即使出现此字段的错误。
我添加的代码:
<?php
$this->registerJs('
jQuery("#' . $form->getId() . '").yiiActiveForm("add", {
"id": "description",
"name": "description",
"container": ".field-description",
"input": "#description",
"validate": function(attribute, value, messages, deferred, $form) {
yii.validation.required(value, messages, {
"message": "Description cannot be blank."
});
yii.validation.string(value, messages, {
"message": "Description must be a string.",
"min": 135,
"tooShort": "Description should contain at least 135 characters.",
"max": 160,
"tooLong": "Description should contain at most 160 characters.",
"skipOnEmpty": 1
});
}
});
', View::POS_LOAD);
?>
到目前为止,我获得的唯一成功是添加
'validateOnSubmit'=>false
到$ form选项。但是这也会从其他字段中跳过错误