zoukankan      html  css  js  c++  java
  • 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';
        }
    
    });
  • 相关阅读:
    android 入门-Activity及 字体
    android 入门-安装环境
    PS 零基础训练1
    txt操作
    C#重绘TabControl
    ini操作
    C#编写ActiveX控件
    远程目录和文件判断
    c#一些操作
    c#消息窗体
  • 原文地址:https://www.cnblogs.com/cart55free99/p/4034817.html
Copyright © 2011-2022 走看看