2016-12-03 6 views
0

フィールドフィールド1はフォーム提出でrequiredです。しかし、フォームを開くと、ラベルの前に 'has-success'という緑色のチェックマークが表示されます。フィールドが有効であるかのように、フィールドには何も入力されていません。angularjsフォームに 'no-success'マークを入力しないでください。

<div class="form-group" 
    ng-class="{'has-error':Form.field1.$dirty && Form.field1.$invalid, 'has-success':Form.field1.$valid}"> 
    <label class="control-label symbol required"> 
     My Field 
    </label> 
    <ui-select multiple tagging tagging-label="true" ng-model="myModel.myfield1" name="field1" theme="bootstrap" title="Choose your answer" required> 
     <ui-select-match placeholder="This is to be completed"> 
      {{$item}} 
     </ui-select-match> 
     <ui-select-choices repeat="r in mydata.datafield1 | filter: $select.search"> 
      {{r}} 
     </ui-select-choices> 
    </ui-select> 
    <span class="success text-small" ng-if="Form.field1.$valid">This is correct!</span> 
</div> 

答えて

1

あなたは、私はこのコードを取得する行動見ることができるように私は、あなたのためplnkrを作った2 編集:

HTML

<div ng-controller="foo"> 

<form name="Form"> 
    <div class="form-group" ng-class="{'has-error':Form.field1.$dirty && Form.field1.$invalid, 'has-success':Form.field1 && Form.field1.$valid}"> 
    <!-- You have to check for Form.field1 property when putting the form valid as well--> 
    <label class="control-label symbol required"> 
     My Field 
    </label> 
    <ui-select multiple tagging tagging-label="true" ng-model="myModel.myfield1" name="field1" theme="bootstrap" title="Choose your answer" required> 
     <ui-select-match placeholder="This is to be completed"> 
      {{$item}} 
     </ui-select-match> 
     <ui-select-choices repeat="r in mydata.datafield1 | filter: $select.search"> 
      {{r}} 
     </ui-select-choices> 
    </ui-select> 
    <span class="success text-small" ng-if="Form.field1.$valid">This is correct!</span> 
    </div> 
</form> 

</div> 

コントローラ

angular.module('myapp', ['ui.select', 'ngSanitize']) 
    .controller('foo', function($scope) { 

    $scope.mydata = { 
    datafield1: ['Option1', 'Option2', 'Option3'] 
    } 

}); 

http://plnkr.co/TKj2sx

+0

私はNGクラスに$ dirty'。 'これをForm.field1を追加しましたが、ええ、成功チェックマークが消えているが、今、別の問題がポップアップし、成功メッセージは、デフォルトで黒に示されています。しかし、一度sthが入力されると、それは緑色になり、成功マークが現れますが、私がフィールドをきれいにすると、成功マークはまだそこにあります! – cplus

+0

さて、私は答えを編集しました。 'Form.field1。$ dirty'を' Form.field1'に変更してください – lealceldeiro

+0

新しい編集でも全く機能しません。同じ話で、チェックマークと成功メッセージの両方が表示されます。 – cplus

関連する問題