Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox unresponsive after errors #7

Open
cimm opened this issue Jun 5, 2020 · 2 comments
Open

Checkbox unresponsive after errors #7

cimm opened this issue Jun 5, 2020 · 2 comments

Comments

@cimm
Copy link

cimm commented Jun 5, 2020

Rails adds a field_with_errors wrapper element around the invalid form element after submitting the form. This is used to style the form element with CSS (red border around an input field with invalid data for example).

The custom Fomantic UI checkbox (the iOS like toggle element) does not correctly handle this extra wrapper element making the field unresponsive: you can no longer check or uncheck the custom Fomantic UI checkbox.

As a workaround we can tell Rails not to add the wrapper element by adding config.action_view.field_error_proc = Proc.new { |html_tag, instance| html_tag.html_safe } to the config/application.rb file but this means we can no longer style form fields with errors.

Tested with fomantic-ui-sass 2.8.3 in a Rails 6.0.2 application.

@cimm
Copy link
Author

cimm commented Jun 19, 2020

I also reported this upstream: fomantic/Fomantic-UI#1529

@shanecav84
Copy link
Collaborator

I've used this which is janky but might work for you:

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  html = nil
  if html_tag.match?(/checkbox|label/)
    html = html_tag
  else
    html = <<~HTML
      <div class='field error'>
        #{html_tag}
      </div>
    HTML
  end
  html.html_safe
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants