加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 在解雇时显示的Bootstrap模态验证

发布时间:2020-12-17 17:45:22 所属栏目:安全 来源:网络整理
导读:我在AngularJS中有一个表单视图,我使用Angular-ui中的一个模态来显示我的表单.功能方面,一切都很好,但是,当我关闭表单时,如果表单无效,则显示验证弹出窗口. 这就是它的样子: 当表单打开时,弹出窗口根本不显示,但只有当我单击取消并且它开始消失时才会显示.
我在AngularJS中有一个表单视图,我使用Angular-ui中的一个模态来显示我的表单.功能方面,一切都很好,但是,当我关闭表单时,如果表单无效,则显示验证弹出窗口.

这就是它的样子:

当表单打开时,弹出窗口根本不显示,但只有当我单击取消并且它开始消失时才会显示.

HMTL:

<form name='newGroupForm'>
    <div class="modal-body">
            <label for="groupName">Group Name:
                <input id="groupName" type="text" ng-model='newGroup.name' required>
            </label>
            <br/>
            <label for="groupDesc">Group Description:
                <input id="groupDesc" type="text" ng-model='newGroup.desc'>
            </label>
            <br/>
            <label for="groupOwner">Group Name:
                <select id="groupOwner" type="text"  ></select>
            </label>
    </div>
    <div class="modal-footer">
        <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
        <button class="btn btn-primary" type="button" ng-click="submit()" ng-disabled="newGroupForm.$invalid">Create</button>
    </div>
</form>

模态控制器:

spApp.controller('newGroupCtrl',function newGroupCtrl($scope,$modalInstance,groupService){
        $scope.newGroup = {
            name:null,desc: null
        };

        $scope.submit = function(){
            $modalInstance.close($scope.newGroup);
        }
        $scope.cancel = function (){
            $modalInstance.dismiss('Cancelled group creation');
        };
    }
);

解决方法

将novalidate属性添加到表单以禁用验证中内置的浏览器:

<form name="myForm" novalidate >

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读