gpt4 book ai didi

javascript - 具有动态选择字段的表单无法验证

转载 作者:行者123 更新时间:2023-11-28 01:58:12 25 4
gpt4 key购买 nike

这里我基本上设置了3个选择列表

<label for="organization">Organization</label>
<select ng-change="setOrganization()" ng-model="form.organization"
ng-options="o.name as o.displayName for o in organizations" required></select>

<label for="board">Board</label>
<select ng-change="setBoard()" ng-model="form.board"
ng-options="b.id as b.name for b in boards" required></select>

<label for="board">List</label>
<select ng-change="setList()" ng-model="form.list"
ng-options="l.id as l.name for l in lists" required></select>

JS:

$scope.setOrganization = function(){
$scope.lists = {};

mySerivce.get('....', function(boards){
$scope.boards = angular.fromJson(boards);
$scope.$apply();
});
};

$scope.setBoard = function(){
mySerivce.get('...', function(lists){
$scope.lists = angular.fromJson(lists);
$scope.$apply();
});
};

因此,当选择一个组织时,我会获取董事会并使用董事会数据填充第二个选择字段。同样,当选择一个板时,将获取分配给该板的所有列表,并使用该数据设置第三个选择字段。在所有选择字段都具有选定值之前,表单将保持无效。

当用户更改组织时,所有字段都会被清除。然而 form.$valid 对象仍然是 true。哪里有问题?当未选择任何值时,该表单必须无效,因为这些字段是必需的。有什么想法吗?

最佳答案

试试这个,它将验证选择值是否未设置。很高兴它起作用了。

mySerivce.get('....', function(boards){
$scope.boards = angular.fromJson(boards);
$scope.form.board = null;
$scope.$apply();
});

关于javascript - 具有动态选择字段的表单无法验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18790926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com