Return client-side confirmation "Missed typeError: cannot read the presence property is undefined"

I have 2 forms on the same page for the User model - and this is the problem why I get the error Uncaught TypeError: Cannot read property 'presence' of undefined . When I remove one form_for @user , so Client side validation works well. But no, if there are two models and two @user forms on the same page.

But the problem is that I need to have this model and form on the same page twice. Is there any way to solve this problem?

+4
source share
2 answers

For me, the second error you described in the comments, i.e. Uncaught TypeError: Cannot read property 'first_user[name]' of undefined , apparently was caused by the transposed form identifier.

There is a problem with ClientSideValidation:

https://github.com/bcardarella/client_side_validations/issues/325

Adding html => { id: 'user_new' } to the form_for call solved the problem. Now I call a method like this (modified from the original Devise template):

 <%= form_for(resource, :as => resource_name, :validate => true, :html => { id: 'user_new' }, :url => registration_path(resource_name)) do |f| %> 

NTN.

+2
source

Ensure that both users use different parameter identifiers:

 <!-- First form for user --> <%= form_for(@user, :as => :first_user) do |f| %> ... <% end %> <!-- Second form for user on the same page --> <%= form_for(@user, :as => :second_user) do |f| %> ... <% end %> 
+1
source

Source: https://habr.com/ru/post/1412332/


All Articles