Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对包含ng消息的生成字段进行表单验证_Javascript_Angularjs_Validation_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Javascript 对包含ng消息的生成字段进行表单验证

Javascript 对包含ng消息的生成字段进行表单验证,javascript,angularjs,validation,angularjs-directive,angularjs-scope,Javascript,Angularjs,Validation,Angularjs Directive,Angularjs Scope,我花了一天的时间让表单验证在生成的字段上处理新的ng消息,但并没有成功。我阅读了angular文档,在github问题上,ng消息不支持ng repeat,因为它不插入字段。因此,我决定走jquery路线,自己构建dom,编译它,并用生成的代码替换元素,之后我当然也无法工作。因此,我们非常感谢您的帮助。这是我的html: .... <app-field ng-repeat="field in fields" field="field" ng-model="selected[fiel

我花了一天的时间让表单验证在生成的字段上处理新的ng消息,但并没有成功。我阅读了angular文档,在github问题上,ng消息不支持ng repeat,因为它不插入字段。因此,我决定走jquery路线,自己构建dom,编译它,并用生成的代码替换元素,之后我当然也无法工作。因此,我们非常感谢您的帮助。这是我的html:

....
    <app-field ng-repeat="field in fields" field="field" ng-model="selected[field.name]" form="form" type="input"></app-field>

    <fieldset class="form-group">
        <label for="field1s">static field 1</label>
        <input name="field1s" type="text" ng-model="selected['field1']" class="form-control" required="">
        <ng-messages for="form['field1'].$error">
            <ng-message when="required">Is required</ng-message>
        </ng-messages>
        <label for="field2s">static field 2</label>
        <input name="field2s" type="text" ng-model="selected.field2" class="form-control" required="" ng-maxlength="10" ng-minlength="2">
        <ng-messages for="form.field2s.$error">
            <ng-message when="required">Is required</ng-message>
            <ng-message when="maxlength">Max length 10</ng-message>
            <ng-message when="minlength">MIn length 2</ng-message>
        </ng-messages>
    </fieldset>
。。。。
我看没有理由不这样做。这里有一个提示:


非常感谢您的帮助…

您需要在每个ng重复中包含ng表单元素,以便动态字段验证能够工作。我已经修复了字段1下面的plunker中的问题。


是必需的
阿尔法误差
我已经注释掉了您编写的自定义JQuery代码。因为它不再需要了


有关更多信息,请参阅此页。关于这个问题。

不是一个真正的解决方案,但根据twitter上的@yearofmoo,“随着Angular 1.4(可能是1.3)的下一个版本的发布,您将能够通过ngRepeat让ngMessages呈现服务器端错误。更多详细信息将很快发布。”
<form name="form">

<ng-form name="myform">
    <input name="field1s" type="text" ng-model="selected['field1']" class="form-control" ng-required="true" ng-pattern="/^[0-9a-zA-Z]+$/">
            <ng-messages for="form.myform['field1s'].$error">
                <ng-message when="required">Is required</ng-message>
                <ng-message when="pattern">alpha error </ng-message>
            </ng-messages>
</ng-form>

</form>