Using error_html with b.use

34 views
Skip to first unread message

David Long

unread,
Mar 26, 2014, 11:31:41 AM3/26/14
to plataformate...@googlegroups.com
I'm trying to setup SimpleForm to use Zurb Foundation style errors. The HTML for an error in Foundation looks something like the following:

<label class="error">Name</label>
<input type="text" name="user[name]" class="error" />
<small class="error">Name is required</small>

To get something similar to that working with SimpleForm, I setup my default wrapper as follows:

config.wrappers :default, class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b|
    b.use :html5
    b.use :placeholder
    b.optional :maxlength
    b.optional :pattern
    b.optional :min_max
    b.optional :readonly

    ## Inputs
    b.use :label, error_html: { class: :error }
    b.use :hint,  wrap_with: { tag: :small, class: :hint }
    b.use :input, error_html: { class: :error }
    b.use :error, wrap_with: { tag: :small, class: :error }
end

When I generate an error in the form, though, the label and input don't have the error class. I'm using SimpleForm 3.0.1

Rafael Mendonça França

unread,
Mar 26, 2014, 12:25:37 PM3/26/14
to PlataformaTec - SimpleForm
This is not support. Does the error class need to be in the input and on the label? Would not it work if you put the class in the wrapper?

--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Long

unread,
Mar 26, 2014, 1:37:27 PM3/26/14
to plataformate...@googlegroups.com
Foundation adds margins to the input, unless it has the "error" class on the input itself. I've added a workaround in the CSS to remove the margin if the wrapper has the class "field_with_errors", but was hoping there was a solution that didn't require customizing the CSS. I know I can add the error_class on each input, but that's not a very good solution.


--
You received this message because you are subscribed to a topic in the Google Groups "SimpleForm" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/plataformatec-simpleform/I9RzwZKniGw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to plataformatec-simp...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Do not be overcome by evil, but overcome evil with good.  - Romans 12:21 ESV

Dave Long

Rafael Mendonça França

unread,
Mar 26, 2014, 1:44:40 PM3/26/14
to PlataformaTec - SimpleForm

error_class on input do the same as error_class on wrapper. It will add the class to wrapper as it is being added now. It does work if you change the :field_with_errors class to error.

Reply all
Reply to author
Forward
0 new messages