• angular checkbox required


    Here is the fiddle http://jsfiddle.net/lumixraku/xgLz7d4j/2/

    html

    <body ng-app="app">
        <div ng-controller='controller'>
            <ng-form name="formName">
                <input type="text" ng-model="val1" required/>
                <div ng-show="myForm.items" ng-repeat="item in myForm.items">
                    <label>
                        <input type="checkbox" name="group[]" ng-model="$parent.selectedValue[item.id]" value="{{item.id}}" ng-required="!someSelected($parent.selectedValue)" />{{item.sId}}</label>
                </div>{{selectedValue}}
                <input type="submit" ng-disabled="formName.$invalid">
                    {{formName.$invalid}}
            </ng-form >
        </div>
    </body>

    JS

    app = angular.module('app', []);
    
    app.controller('controller', function ($scope) {
        $scope.myForm = {};
        $scope.selectedValue = {};
        $scope.myForm.items = [{
            id: 1,
            sId: "analog"
        }, {
            id: 2,
            sId: "isdn"
    
        }, {
            id: 3,
            sId: "dsl"
        }];
        $scope.someSelected = function (obj) {
            console.log('some selecgted');
            var rs=Object.keys(obj).some(function (key) {
                return obj[key];
            });
            console.log(rs);
            return rs;
        }
        $scope.submitForm = function(){
            $scope.clickSubmit = 'clickSubmit';
        }
    
    });
  • 相关阅读:
    企业级 SpringBoot 教程 (九)springboot整合Redis
    03 网格系统
    02 表单
    01 排版
    客户端调用webSerices
    sql 一行转多行
    sql 多行转一行
    时间差计算 Stopwatch
    sql 游标
    Linq连接查询
  • 原文地址:https://www.cnblogs.com/cart55free99/p/4034817.html
Copyright © 2020-2023  润新知