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
Automate form wrapper classes #576
Comments
+1 I've been trying to find a way to do this since switching from Formtastic... |
This is not possible right now, unless you do some sort of monkey patching, or add it for the required inputs manually. |
Alright then, here's a monkey patch for anyone who might be interested: # Hack to add object_name + attribute_name to wrapper classes:
module SimpleForm
module Wrappers
class Root < Many
private
alias_method :html_classes_orig, :html_classes
def html_classes(input, options)
css = html_classes_orig(input, options)
css << "#{input.object_name}_#{input.attribute_name}"
css
end
end
end
end I can turn this into a pull request if there's any chance of @plataformatec merging it... |
I'm unsure this is something we'd add by default, and I can't think of a good solution right now (sorry I'm sleepy).. It's hard to make it work for everyone, some want all possible css classes, some want to cleanup the html output 😃. @rafaelfranca thoughts on this one? |
+1 @emptyflask for the monkey patch. I think adding a verbose wrapper option to the config is a value add. |
I too would like this behavior to at least be an option. I style forms that way quite frequently and it is one of the reasons I'm still using Formtastic. But thanks to this monkey patch I may finally switch to Simple Form. |
@rafaelfranca I think we should stick with current implementation and add that monkey patch to the Wiki page. Thoughts? |
I don't like the idea to add Yet Another Configuration Option ™️. I think is better to generate this class by default and use the Like we are doing in this one https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/wrappers/root.rb#L27 |
From my perspective as someone who wants to switch from formtastic to simple_form, I just need a way to have a CSS selector for a specific error/hint wrapper on a particular field, preferably without monkey-patching. The easiest way to get this would just be a field-specific class/id on the surrounding wrapper by default. |
Should not be hard to do what I suggested. I'll take a look at this tomorrow. |
Hey guys, just pushed b5f2ea4 for this based on @rafaelfranca input and @emptyflask code 😄. |
❤️ |
Thanks! |
Thank you @lucasmazza for adding this to 2.1.dev. It is very useful for customizing form layouts because the wrapper is the outermost container for each logical grouping of label, input, errors, etc. |
Having some trouble accomplishing the task of changing the way the wrapper is being assigned a class.
My objective, is to have the wrapper div receive a class that matches the field name.
From:
To:
When building a more complex layout for the form having these unique identifiers would be greatly appreciated. If anyone has a suggestion for how to do this other than setting the wrapper class in each line of each element, I would appreciate the help.
Thank you
Zach
The text was updated successfully, but these errors were encountered: