文本区域上的AngularJS ng minlength/ng maxlength显示错误消息,但表单在单击提交按钮时被提交 您的评论: 需要说明。 说明不应少于50个字符。 说明不应超过200个字符。 提交 $scope.Submit=函数(){ var乘积={ Title:$scope.Title, description:$scope.description, 名称:$scope.name, 评级:3 } var res=$http({ url:“http://localhost:44826/api/review", 方法:“张贴”, 数据:$.param(产品), 标题:{ “内容类型”:“application/x-www-form-urlencoded;charset=UTF-8” } }); 成功的原因( 函数(数据、状态、标题、配置){ //控制台错误(“回购错误”、状态、数据); $scope.isVisible=false; $scope.FeedMsg=true; $scope.successsg=“反馈已成功提交…”; }); res.error(函数(数据、状态、标题、配置){ 警报(“错误”); }); }
当我在文本区域中输入少于50或超过200个字符的文本时,它显示错误消息,但在单击提交按钮时表单正在提交。 如果我没有输入任何内容,则表单未提交到服务器显示错误消息 当显示错误消息时,我希望表单不要在单击“提交”时提交…请尝试以下代码: HTML: 将表单名称作为参数传递到文本区域上的AngularJS ng minlength/ng maxlength显示错误消息,但表单在单击提交按钮时被提交 您的评论: 需要说明。 说明不应少于50个字符。 说明不应超过200个字符。 提交 $scope.Submit=函数(){ var乘积={ Title:$scope.Title, description:$scope.description, 名称:$scope.name, 评级:3 } var res=$http({ url:“http://localhost:44826/api/review", 方法:“张贴”, 数据:$.param(产品), 标题:{ “内容类型”:“application/x-www-form-urlencoded;charset=UTF-8” } }); 成功的原因( 函数(数据、状态、标题、配置){ //控制台错误(“回购错误”、状态、数据); $scope.isVisible=false; $scope.FeedMsg=true; $scope.successsg=“反馈已成功提交…”; }); res.error(函数(数据、状态、标题、配置){ 警报(“错误”); }); },angularjs,validation,angularjs-directive,Angularjs,Validation,Angularjs Directive,当我在文本区域中输入少于50或超过200个字符的文本时,它显示错误消息,但在单击提交按钮时表单正在提交。 如果我没有输入任何内容,则表单未提交到服务器显示错误消息 当显示错误消息时,我希望表单不要在单击“提交”时提交…请尝试以下代码: HTML: 将表单名称作为参数传递到Submit()函数中 例如 <form name="reviewForm" ng-submit="Submit();" novalidation> <div> <
Submit()
函数中
例如
<form name="reviewForm" ng-submit="Submit();" novalidation>
<div>
<div class="label label-primary first">Your Review:</div>
<div class="form-group has-error second">
<textarea id="Description" name="Description" ng-minlength=50 ng-maxlength=200 ng-model="Description" ng-required="true" style="width: 500px; height: 200px;"></textarea>
<label class="control-label" ng-show="submitted && reviewForm.Description.$error.required">Description is required.</label>
<label class="control-label" ng-show="submitted && reviewForm.Description.$error.minlength">Description is should not be less than 50 charecters.</label>
<label class="control-label" ng-show="submitted && reviewForm.Description.$error.maxlength">Description is should not be more than 200 charecters.</label>
</div>
<div style="clear:both;"></div>
</div>
<div>
<div>
<button type="submit" class="btn btn-primary" name="btnSubmit" ng-disabled="reviewForm.$invalid" ng-click="submitted=true">Submit</button>
</div>
</div>
</form>
$scope.Submit = function () {
var product = {
Title: $scope.Title,
description: $scope.Description,
name: $scope.Name,
Rating: 3
}
var res = $http({
url: "http://localhost:44826/api/review",
method: "POST",
data: $.param(product),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
});
res.success(
function (data, status, headers, config) {
//console.error('Repos error', status, data);
$scope.isVisible = false;
$scope.FeedMsg = true;
$scope.SuccessMsg = "Feedback has been submitted Sucessfully...";
});
res.error(function (data, status, headers, config) {
alert('error');
});
}
<form name="reviewForm" ng-submit="Submit(reviewForm);" novalidation>
...
</form>
希望这有帮助。您有提交功能吗?如果是,那么您可以共享吗???@sreehari您可以提供
Submit()
函数的代码吗?添加了Submit函数。
$scope.Submit = function(reviewForm) {
if (reviewForm.$valid) {
var product = {
Title: $scope.Title,
description: $scope.Description,
name: $scope.Name,
Rating: 3
};
var res = $http({
url: "http://localhost:44826/api/review",
method: "POST",
data: $.param(product),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
});
res.success(
function(data, status, headers, config) {
//console.error('Repos error', status, data);
$scope.isVisible = false;
$scope.FeedMsg = true;
$scope.SuccessMsg = "Feedback has been submitted Sucessfully...";
});
res.error(function(data, status, headers, config) {
alert('error');
});
}
};