Simple Form Error Notification

◇◆丶佛笑我妖孽 提交于 2019-12-03 17:14:46

Make sure you have similar line in ur initializer's wrapper

b.use :error, wrap_with: { tag: 'span', class: 'help-block' }

as you mentioned in ur question, please remove required: false, and to remove the '*' for required, change it in config/locale/simple_form.en.yml

required:
  text: 'required'
  mark: ''

Does anyone know how to address this problem?

Because you're able to use an object in the registration form, it means you have some liberty over how you display the errors. It would be a different story if you were trying to achieve the same with login (as login does not use a form)

--

Form

We've done this before (you can see here - click "Register" at top):

#app/views/devise/registrations/new.html.erb
<%= f.email_field :email, :placeholder => "email" %>
<div class="error"><%= devise_resource.errors[:email].first if devise_resource.errors[:email].present? %></div>

Considering the form uses devise_resource in the form_for object - this should allow you to display the errors inline

You say you are using modals? But you do not post ajax (no remote: true on your form). So I will describe what I think happens now. You do not post ajax, so you post html, so it chooses the format.html path, and on error your controller redirects to root-path, with an error message. Instead it should re-render the form.

So uncommenting the commented line in your create action should work :) (and deleting the current format.html line obviously).

Ofcourse the re-render will not be a modal. When using modals, and you want the form to remain open, you will have to use ajax and replace the form with a re-rendered version in case of error.

Simple-form, when given an object with validation-errors, will automatically show the errors inline.

The problem with error validation is resolved if:

  1. remove: f.error_nofication from the simple_form call; and
  2. insert: <%= devise_error_messages! %> inside the form-inputs field.

If you have validations on your user model and also use devise validatable, the error list at the top of the form will duplicate the errors. Remove one or the other of the validations and you will have the errors working.

I cannot figure out why simple form does not render the errors - but this is a solution.

I have decided to remove simple form from my application - I can't read the documentation and so many questions posted on Stack Overflow relating to using it with devise do not get answered. I cannot see its benefits.

As for the modal - I am going to try using this. http://bootstrapvalidator.com (fingers crossed). I hope this answer helps someone. I have been trying to set up devise for 3 months - with 3 weeks solid daily effort in trying to understand the docs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!