/ yii2

yii2-activeform

使用 JavaScript 可以更加灵活操作ActiveForm。

您可以更新某些字段的错误信息:

// add error
$('#contact-form').yiiActiveForm('updateAttribute', 'contactform-subject', ["I have an error..."]);
 
// remove error
$('#contact-form').yiiActiveForm('updateAttribute', 'contactform-subject', '');

Or update the whole form and, optionally, summary at once:

$('#contact-form').yiiActiveForm('updateMessages', {
    'contactform-subject': ['Really?'],
    'contactform-email': ['I don\'t like it!']
}, 'There are errors!');