0

ngMessage の奇妙な動作に遭遇しました

angular uiブートストラップタブに検証

最初のタブでは機能しません

コード

js

angular
        .module('app', ['ngMessages','ui.bootstrap'])
        .controller('MainCtrl', MainCtrl);
        function MainCtrl() {}

html

<body class="container" ng-app="app" ng-controller="MainCtrl as main">
        <uib-tabset active="0" justified="true">
            <uib-tab index="0">
                <uib-tab-heading>
                  <ul class="header">
                    <li class="title">title 1</li>
                    <li class="description">Descr 1</li>
                  </ul>
                </uib-tab-heading>
                <div class="tab-pane-general">
                   <form name="form" novalidate>
                        <div class="form-group" ng-class="{ 'has-error': form.location.$touched && form.location.$invalid }">
                            <label>Name</label>
                            <input type="text" name="location" class="form-control" 
                                ng-model="main.location"
                                ng-minlength="5"
                                ng-maxlength="10"
                                required>
                            <div class="help-block" ng-messages="form.location.$error" ng-show="form.location.$touched">
                                <div class="alert alert-danger" role="alert">
                                    <p ng-message="minlength">Your name is too short.</p>
                                    <p ng-message="maxlength">Your name is too long.</p>
                                    <p ng-message="required">Your name is required.</p>
                                </div>
                            </div>         
                        </div>
                    </form>
                </div>
            </uib-tab>
            <uib-tab index="1">
                <uib-tab-heading>
                  <ul class="header">
                    <li class="title">title 2</li>
                    <li class="description">Descr 2</li>
                  </ul>
                </uib-tab-heading>
                <div class="tab-pane-general">
                    <form name="form" novalidate>
                        <div class="form-group" ng-class="{ 'has-error': form.location.$touched && form.location.$invalid }">
                            <label>Name</label>
                            <input type="text" name="location" class="form-control" 
                                ng-model="main.location"
                                ng-minlength="5"
                                ng-maxlength="10"
                                required>
                            <div class="help-block" ng-messages="form.location.$error" ng-show="form.location.$touched">
                                <div class="alert alert-danger" role="alert">
                                    <p ng-message="minlength">Your name is too short.</p>
                                    <p ng-message="maxlength">Your name is too long.</p>
                                    <p ng-message="required">Your name is required.</p>
                                </div>
                            </div>         
                        </div>
                    </form>
                </div><!--/tab-pane-general -->
            </uib-tab>
            <uib-tab index="2">
                <uib-tab-heading>
                  <ul class="header">
                    <li class="title">title 3</li>
                    <li class="description">Descr 3</li>
                  </ul>
                </uib-tab-heading>
                <div class="tab-pane-general">
                    TAB THREE
                </div><!--/tab-pane-general -->
            </uib-tab>
        </uib-tabset>
</body>

http://codepen.io/whisher/pen/QEyyzz

バグですか?

何か案が ?

アップデート

私は同じ名前の入力を設定した実際のアプリでそれを解決しました^^

4

2 に答える 2

1

本当に 2 つのフォーム タグが必要ですか? すべてのフォームタグには独自の検証があります。したがって、タブ コントロール全体に対して 1 つの検証が必要な場合は、フォーム タグを 1 つだけ配置する必要があります。

于 2016-06-09T09:19:04.077 に答える
-1

あなた<form>は同じ名前を持っています。したがって、firstname1と second をname2all に変更すると、正常に動作します。

ここでAngular Form Validationの詳細を読むことができます

于 2016-06-09T09:19:05.137 に答える