gpt4 book ai didi

ruby-on-rails - client_side_validations 'Cannot read property ' 用户[电子邮件 ]' of undefined'

转载 作者:行者123 更新时间:2023-12-04 06:20:38 25 4
gpt4 key购买 nike

所以我试图让 client_side_validations gem 工作,当我跳出我的电子邮件字段时,我收到此错误:

Uncaught TypeError: Cannot read property 'user[email]' of undefined 

这是我的表单助手:

<%= form_for(resource, :as => resource_name, :class => "send-with-ajax", :url => user_registration_path(resource), :validate => true) do |f| %>
<%= f.email_field :email, :id => "form-email", :placeholder => "your-email@address.com", :input_html => {:autofocus => true}, :validate => true %>
<%= f.submit :label => "Submit", :value => "Sign Me Up!" %>
<div class="ajax-response"><%= devise_error_messages! %></div>
<% end %>

生成此 HTML:

<form accept-charset="UTF-8" action="/users" class="new_user" data-validate="true" id="new_user" method="post" novalidate="novalidate">
<input name="utf8" type="hidden" value="&#x2713;" />
<input name="authenticity_token" type="hidden" value="9JdqaiushdauhsdioauhdoiuhNLSAVCGrc+PLJAQ=" />
<input data-validate="true" id="form-email" input_html="{:autofocus=&gt;true}" name="user[email]" placeholder="your-email@address.com" size="30" type="email" />
<input label="Submit" name="commit" type="submit" value="Sign Me Up!" />
<div class="ajax-response"></div>
</form>

编辑 1: 即使我将表单助手从 f.email_field :email 更改为 f.text_field :email...我仍然收到此错误。

最佳答案

所以我找到了解决方案,似乎 client_side_validationsdevise 正在改变表单的 id - 这会破坏 JS验证。

所以解决方案是强制执行表单的 id,所以我的 form_for 助手现在看起来像这样:

<%= form_for(resource, :as => resource_name, :class => "send-with-ajax", :url => user_registration_path(resource), :validate => true, :html => { :id => 'user_new' }) do |f| %>

我找到了这个 solution here .

关于ruby-on-rails - client_side_validations 'Cannot read property ' 用户[电子邮件 ]' of undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10909337/

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