Yii表格

时间:2015-05-09 09:01:07

标签: javascript php angularjs forms yii

我在Yii动态表单中使用AngularJS v1.3.15进行表单验证,但似乎角度验证适用于输入名称。问题是输入名称是数组格式,例如:name="LoginForm[username]"。我在这里复制我的代码:

   <div class="col-md-4 col-md-offset-4 m-t-lg" ng-app="validationApp" ng-controller="mainController">
            <section class="panel">
                <header class="panel-heading text-center"><strong>Admin Sign in </strong> </header>
                <?php 
                        $form=$this->beginWidget('CActiveForm', array(
                            'id'=>'formLogin',
                            'htmlOptions'=> array('name'=>'userForm', 'class'=>'panel-body', 'ng-submit'=>'submitForm($event)', 'novalidate'=>'true'),
                            'action'=>'#',
                            'enableAjaxValidation'=>false,
                        )); 
                    ?>
                    <div class="form-group" ng-class="{'has-error' :  userForm.username.$invalid && !userForm.username.$pristine}">
                        <label class="control-label">Email</label> 
                        <?php echo $form->emailField($model, 'username', array('placeholder'=>'test@example.com', 'class'=>'form-control', 'ng-model'=>'user.username', 'ng-pattern'=>"/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", 'required'=>'true', 'id'=>'username')); ?>
                        <?php echo $form->error($model,'username'); ?>
                    </div>
                    <div class="form-group" ng-class="{'has-error' :  userForm.password.$invalid && !userForm.password.$pristine}">
                        <label class="control-label">Password</label> 
                        <input type="password" placeholder="Password" ng-minlength="6" class="form-control" name="password" ng-model="user.password" required>
                    </div>
                    <div class="checkbox">
                        <label> <input type="checkbox"> Keep me logged in
                        </label>
                    </div>
                    <button type="submit" class="btn btn-info" ng-disabled="userForm.$invalid">Sign in</button>
                <?php $this->endwidget(); ?>
            </section>
        </div>
    </div>

这是角度控制器的脚本代码:

      var app = angular.module('validationApp',[]);
         app.controller('mainController', function($scope) {
            $scope.submitForm = function($event){
            if ($scope.userForm.$valid){
                $scope.submit();
            } else $event.preventDefault();
         } 
      });

如果我将输入的名称更改为单个单词,例如“username”和“password”,但它在当前情况下不能使用名称“LoginForm [username]”,它可以正常工作。它与密码字段的工作正常,因为它的普通名称,但用户名字段不一样。