0

在这里,我从服务器端收到名为“重复标题”的错误消息。但我的问题是,在此示例中,标题长度应为 24 个字符。但如果标题已经存在,那么它会显示一条错误消息。

但我的要求是,如果在我们输入下一个字母后是重复的标题,那么重复的消息将需要消失......

这是代码...

<div class="col-md-12">
        <form name="taskForm" class="form-horizontal" ng-submit="create()">
            <div class="form-group">
                <div class="col-xs-10 col-md-11">
                    <input name="title" type="text" class="form-control place" ng-model="title" id="title" placeholder="Enter Task Timer Here">
                    <span ng-show="duplicateTitle" class="text-danger">Duplicate Task Title. Please choose Unique Title!</span>
                </div>

                <div class="col-xs-1">
                    <span ng-click="create()" class="glyphicon glyphicon-plus plusIcon"></span>
                </div>

            </div>

        </form>
    </div>

控制器文件是...

$scope.create = function () {
            var currentDate = new Date();

            for (var i = 0; i < $scope.tasks.length; i++) {
                if ($scope.tasks[i].title === this.title) {
                    $scope.duplicateTitle = true;

                    console.log("duplictae" + $scope.duplicateTitle);
                    return;
                }
            }


            var task = new Tasks({
                'title': this.title,
                'description': this.description,
                'duration': 0,
//              'lastStart': currentDate
            });

            task.$save(function (response) {
                //$location.path('tasks');
                $scope.duplicateTitle = false;
                //$scope.tasks.push(response);
                $scope.tasks = Tasks.query();
                $scope.title = '';
                $scope.description = '';
            }, function (errorResponse) {
                $scope.error = errorResponse.data.message;
            });
        };
4

1 回答 1

0

您可以向输入添加ng-change="duplicateTitle = false"属性。这将在输入更改后清除错误消息。

于 2014-12-04T11:14:20.407 回答