2016-12-16 15:06:26 2226次浏览 0条回答 0 悬赏 15 金钱

先描述下问题吧:

model里面定义的rules,前端页面鼠标点击空白处没有生效,只有点击提交以后页面刷新才生效了

model里面

//设置场景
    public function scenarious()
    {
        return [
            'edit' => [ 'password' ],
        ];
    }

    public function rules()
    {
        return [

            [ [ 'password' ], 'required', 'on' => [ 'edit' ] ],

        ];
    }

Controller里面:

	public function actionSettingSecurity()
	{
		$model = new UserForm;
		$model->setScenario( 'edit' );
		if ( $model->load( $post = Yii::$app->request->post() ) && $model->validate() ) {
			return $this->render( 'edit', [ 'model' => $model ] );

		}else{
			//var_dump($model->getErrors());
			return $this->render( 'edit', [ 'model' => $model ] );
		}

	}

View页面


<?php $form = ActiveForm::begin( [
                    'id' => 'forme1',
                    'options' => [
                      'class' => 'form-horizontal',
                    ],
                  ] ) ?>

                    <div class="form-group">
                        <?= $form->field( $model, 'password' )->passwordInput( [ 'class' => 'form-control' ] )->label( false ); ?>
                    </div>

                    <div class="form-group">
                        <?= $form->field( $model, 'rePassword' )->passwordInput( [ 'class' => 'form-control' ] )->label( false ); ?>
                    </div>

                    <div class="form-group">
                      <div class="col-sm-offset-4 col-sm-6">
                        <?= Html::submitButton( 'Save' , [ 'class' => 'btn btn-primary' ] ); ?>
                      </div>
                    </div>

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

这个问题困扰了好久了。。。求大神解答

补充于 2016-12-16 15:30

已经解决。

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
xiam
试用期

xiam

注册时间:2016-05-01
最后登录:2017-01-04
在线时长:2小时27分
  • 粉丝0
  • 金钱10
  • 威望0
  • 积分30

热门问题