/ 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!');

水平布局

_serach 中搜索经常会用到行内表单:

// 支持 3 中布局:'default', 'horizontal', 'inline'
use yii\bootstrap\ActiveForm;

$form = ActiveForm::begin(['layout' => 'inline']);

index 中的布局:

<div class="clearfix">
    <div class="pull-left" style="display: inline-block">
        <?= $this->render('_search', ['model' => $searchModel]); ?>
    </div>

    <p class="pull-right" style="display: inline-block">
        <?= Html::a('添加文章', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
</div>