angular 1.2.29版本下 动态添加多个表单、 校验全部、 提交 、ng-form方案

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
<style>
    .hasError{
        border: 1px red solid;
    }
    .errorMsg{
        color: red
    }
</style>
<body ng-app="myApp" ng-controller="myCtrl">
    <button ng-click="addRow()">添加</button>
    <form name="userForm" novalidate  ng-submit="userForm.$valid?submit():‘‘">
        <table>
            <thead>
                 <tr>
                    <th>字段一</th>
                    <th>字段二</th>
                    <th>字段三</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="item in jsonList">
                    <td>
                        <input type="text" readonly ng-model="item.name1">
                    </td>
                    <td>
                        <input type="text" readonly ng-model="item.name2">
                    </td>
                    <td>
                        <input type="text" readonly ng-model="item.name3">
                    </td>
                </tr>
                <tr ng-repeat="item in jsonListAdd">
                    <td>
                        <ng-form name="tel{{$index}}">
                            <input
                            type="text"
                            placeholder="请输入手机号"
                            ng-model="item.name1"
                            required
                            ng-pattern = "/^(13|15|17|18|14)[0-9]{9}$/"
                            name="tel"
                            ng-class="{ ‘hasError‘ : {{‘tel‘ + $index}}.tel.$dirty && {{‘tel‘ + $index}}.tel.$invalid}"
                            >
                            <p ng-show="{{‘tel‘ + $index}}.tel.$dirty && {{‘tel‘ + $index}}.tel.$invalid" class="errorMsg">error message1.</p>
                            <!-- <p>dirty: <span ng-bind="{{‘tel‘ + $index}}.tel.$dirty"></span>    </p>
                            <p>invalid: <span ng-bind="{{‘tel‘ + $index}}.tel.$invalid"></span></p> -->
                        </form>
                    </td>
                    <td>
                        <ng-form name="email{{$index}}">
                            <input type="text"
                            type="text"
                            placeholder="请输入6位验证码"
                            ng-model="item.name2"
                            required
                            ng-pattern = "/^[^\u2E80-\u9FFF]{6,16}$/"
                            name="email"
                            ng-class="{ ‘hasError‘ : {{‘email‘ + $index}}.email.$dirty && {{‘email‘ + $index}}.email.$invalid}"
                            >
                            <p ng-show="{{‘email‘ + $index}}.email.$dirty && {{‘email‘ + $index}}.email.$invalid" class="errorMsg">error message2.</p>
                        </form>
                    </td>
                    <td>
                        <ng-form name="addr{{$index}}">
                            <input type="text"
                            type="text"
                            placeholder="请输入6位验证码"
                            ng-model="item.name3"
                            required
                            ng-pattern = "/^[^\u2E80-\u9FFF]{6,16}$/"
                            name="addr"
                            ng-class="{ ‘hasError‘ : {{‘addr‘ + $index}}.addr.$dirty && {{‘addr‘ + $index}}.addr.$invalid}"
                            >
                            <p ng-show="{{‘addr‘ + $index}}.addr.$dirty && {{‘addr‘ + $index}}.addr.$invalid" class="errorMsg">error message3.</p>
                        </form>
                    </td>

                </tr>
            </tbody>
        </table>

        <button type="submit">提交</button>

    </form>

</body>
    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <!--<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>-->
     <script src="angular.js"></script>
    <script src="three.js"></script>
</html>

js:

var app = angular.module(‘myApp‘, []);
app.controller(‘myCtrl‘, function($scope) {
    $scope.jsonList = [
            {
                name1: ‘name1‘,
                name2: ‘name2‘,
                name3: ‘name3‘
            },
            {
                name1: ‘name1‘,
                name2: ‘name2‘,
                name3: ‘name3‘
            },
            {
                name1: ‘name1‘,
                name2: ‘name2‘,
                name3: ‘name3‘
            }
        ];//原先的数据
    $scope.jsonListAdd = [];//添加的数据
    $scope.addNum = 0;//添加次数

    $scope.regExp = {
        mobile:"/^(13|15|17|18|14)[0-9]{9}$/"
    }
    // 添加
    $scope.addRow = function(){
        $scope.jsonListAddNull = {
            name1: ‘‘,
            name2: ‘‘,
            name3: ‘‘
        };

        $scope.addNum = $scope.addNum + 1;

        if($scope.addNum <= 20){
            $scope.jsonListAdd.push($scope.jsonListAddNull);
        }

    };
    // 提交
    $scope.submit = function(){
        console.log($scope.jsonListAdd);
    };

});
时间: 2024-08-05 23:12:31

angular 1.2.29版本下 动态添加多个表单、 校验全部、 提交 、ng-form方案的相关文章

IE下object元素遮挡div表单

目前遇到这样的一个问题: 我用ActiveX插件做了一个C#的播放器,要将这个插件放到web浏览器中,然后可以通过前台页面来控制视频的播放,暂停还有回放,这个时候发现object的onclick事件无法相应,一搜索,确实是这样.那么怎么办呢?万能的搜索啊,终于有两种解决方案: 1,js监听ActiveX控件的行为.(按照网上给的,行不通,监听失败,原因是很多都是10年左右用vc++写的ocx插件的方法,现在行不通) 2,直接通过js控制. 很明显采用第2个方法,于是新的问题就出现了: 怎么调用?

动态增加响应式表单

页面文件: <form *ngFor="let form of list" [formGroup]="form"> <div class="form-group"> <label>姓名:</label> <input style="color: #000;" type="text" formControlName="name">

下拉选择框改变表单action的简单例子

做了个简单的小例子 用js弄的. form  的代码 1 <form  action=""  method="post" id="formRole"> type的 下拉单 1 2 3 4 5 6 <select name="type" id="type"  onchange="changeAction()">       <option value=&quo

如何清空IE下file文件控件表单里面的值

在IE下由于安全的策略,没法通过$(":file").val('')来清空里面上传的值.那我们只能通过克隆节点的方法来实现清空. 如下: var file = $(":file"); file.after(file.clone().val("")); file.remove(); 这样就可以清空里面的值了. 如何清空IE下file文件控件表单里面的值

C# 如何向Excel添加、删除表单控件

在Excel中,添加的控件可以和单元格关联,我们可以操作控件来修改单元格的内容,在下面的文章中,将介绍在Excel中添加几种不同的表单控件的方法,包括: 添加文本框 单选按钮 复选框 组合框 使用工具:Free Spire.XLS for .NET 8.3 (社区版)PS:下载安装该组件后,注意在项目程序中添加引用Spire.XLS.dll(dll文件可在安装路径下的Bin文件夹中获取),如下图所示 代码示例: 插入Excel表单控件[C#] using Spire.Xls; using Spi

struts之动态方法调用改变表单action属性

一.动态方法调用(DMI:Dynamic Method Invocation) ⒈struts2中同样提供了这个包含多个逻辑业处理的Action,这样就可以在一个Action中进行多个业务逻辑处理.例如:当用户通过不同的提交按钮来提交同一个表单的时候,系统通过不同的方法来处理用户不同的请求,这时候就需要让同一个Action中包含有多个控制处理的逻辑. ⒉动态方法调用有: ①.改变struts.xml中的action中的method属性. ②.改变form表单中的action属性来改变不同提交的请

管理员模式下将当前路径下程序添加到注册表开机启动批处理命令

cd /d %~dp0reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v [注册表键名] /t REG_SZ /d %cd%\[可执行程序文件名] /fpause 以下为删除命令 reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v [注册表键名] pause 原文地址:https://www.

点击含下拉菜单的列表/表单按钮:通过JS创建虚拟按钮并点击

${JsCode} | Get Element Attribute | XPATH=//table[@class='mnubar']//tr//td//span[text()='${MenuArr[0]}' and @class='mnuBtn']/parent::span/table[@class='mnuList']//tr/td[text()='${MenuArr[1]}']/parent::[email protected] 注释: 1.MenuArr为传入的需要点击的按钮路径,如:新增

Angular 表单校验

1.html <form [formGroup]="formModel" (submit)="submit()"> <div> 用户名:<input type="text" formControlName="username"> 电话:<input type="text" formControlName="mobile"> <div