gpt4 book ai didi

ruby-on-rails - 显示验证错误在 angular| 中不起作用$errors 对象为空

转载 作者:行者123 更新时间:2023-12-04 02:17:35 25 4
gpt4 key购买 nike

我有以下形式(在 rails 中)

= form_for([@debate,@argument], html: { class: "form-horizontal", role: "form" , "ng-submit"=>"addArgument('support',$event)", novalidate: true, name: "argumentformsupport"}) do |f|
- if @argument.errors.any?
.alert.alert-danger.alert-dismissable role="alert"
button.close type="button" data-dismiss="alert"
span aria-hidden="true"
| ×
span.sr-only
| Close
h4= "#{pluralize(@argument.errors.count,"error")} prohibited this argument from being saved:"
ul
- @argument.errors.full_messages.each do |msg|
li= msg
= f.hidden_field :side, :value=>side, "ng-model"=>"argument['support'].side"

.form-group

.col-sm-12
= f.text_area :content, class: "form-control", "ng-model"=>"argument['support'].content", required: true, "ng-minlength"=>"100", "ng-maxlength"=>"4000"
textarea.form-control ng-model="argument['support'].content" name="content" required=true ng-minlength="100" ng-maxlength=4000
<div ng-messages="argumentformsupport.content.$error" style="color:maroon" role="alert">
<div ng-message="required">Please type the argument</div>
<div ng-message="minlength">Your field is too short</div>
<div ng-message="maxlength">Your field is too long</div>
</div>

.form-group
.col-sm-4
= f.submit class: "btn btn-success"
.col-sm-3
button.btn.btn-danger type="button" ng-click="debcon.toggleArgumentForm('support')" Cancel

以下是我的应用js代码

var debateApp=angular.module("debate",['ng-rails-csrf', 'yaru22.angular-timeago'])

debateApp.controller("DebateController",["$scope","$http",function($scope,$http){
....
}

ng-messages 根本不起作用。所有的消息都是可见的。我添加了 Angular 消息依赖项,但所有消息仍然可见。

我还检查了 argumentformsupport.content.$errors 对象。它是空的

最佳答案

您的主模块缺少 ngMessages 依赖项。应该看起来像这样:

angular.module("debate",['ngMessages', 'ng-rails-csrf', 'yaru22.angular-timeago'])

当然,您还需要包含适当的 javascript 文件。

参见:https://docs.angularjs.org/api/ngMessages ;

关于ruby-on-rails - 显示验证错误在 angular| 中不起作用$errors 对象为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32999349/

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