<?php

use backend\widgets\ActiveForm;
use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $model common\models\GoodsAttr */
/* @var $form ActiveForm */
?>
<div class="box box-success">
    <div class="box-body">
        <?php $form = ActiveForm::begin([
            'enableClientValidation' => false,
            'id' => 'form-attr',
            'enableAjaxValidation' => true// 需要使用 backend\widgets\ActiveForm 后台自定义表单
        ]); ?>


        <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'value')->textInput(['maxlength' => true]) ?>

<!--        --><?//= $form->field($model, 'sort')->textInput() ?>

        <div class="form-group form-submit">
            <?= Html::submitButton($model->isNewRecord ? Yii::t('common', 'Create') : Yii::t('common', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-success']) ?>
        </div>

        <?php ActiveForm::end(); ?>
    </div>
</div>




<?php
$js = <<<JS
    //表单提交
    $(document).on('beforeSubmit', 'form#form-attr', function() { 
        var form = $(this); 
        //返回错误的表单信息 
        if (form.find('.has-error').length) 
        { 
          return false; 
        } 
        
        //表单提交 
        $.post(form.attr('action'), form.serialize(), (res) => {
            if (res.errcode == 0) {
                $.modal.notify(res.errmsg, 'success', () => {
                    //关闭layer
                    parent.layer.close(parent.layer.getFrameIndex(window.name))
                });
            } else {
                $.modal.error(res.errmsg);
            }
        });
        
        return false; 
      }); 
JS;
$this->registerJs($js);
?>


