In many cases, creating a new Input class is an overhead.
For example, a username on a website, which should look like
Username: twitter.com/ [___________]
The following code:
= f.input :username
will not allow the "twitter.com/" to be placed, but if li/label could be not rendered, or be rendered with helpers, I could do (Slim syntax):
= f.input_wrapper do
= f.label :username
= f.input_tag :username
What are your thoughts?
Just figured out I can use regular form functions (f.label, f.text_field etc.).
f.input adds things such as maxlength, which f.text_field doesn't
And f.input_wrapper would be helpful, instead of writing that <li> tag.
So it's pretty useful.
I think adding this as a feature goes against the intent of the library and would create a lot of complexity. In short, while adding a new input class is an overhead for you, adding a new feature for this in Formtastic is an overhead for everyone :)
This i a perfect candidate for a custom input. You could subclass Formtastic::Inputs::StringInput as StringWithoutWrapperInput in app/inputs/string_without_wrapper_input.rb for something generic (you just need to redefine input_wrapping) or something specific like TwitterUsernameInput which actually includes all the extra markup you need inside the li wrapping (you'd need to redefine to_html probably).
Closing for now.
Hi, could you explain how this goes against the intent of the library? The intent of the library, from what I understand, is to make rendering forms simple with a set of powerful features. Yet if I can't render labels or input tags separate from each other, how exactly is that simple or powerful? It actually renders it quite useless for complicated form layouts.
That's one of the main reasons I'd stick with simple_form. Do you have any plans to develop this in the future?
@damien-roche the intent of the library was originally to create a standard mark-up pattern (where none existed at the time) to speed up development for me on my projects (which were very heavy on data input), shifting the clutter, logic and noise out of my views and into plain ruby helpers and objects. Obviously the landscape has changed over time, but as a principal, complex and noisy views are a bad smell for me, and I will always seek to extract that into pure ruby. Helpers and custom inputs do exactly this.
The specific case mentioned in this request is still a great candidate for a custom input, rather than 5 lines of ERB, even if it's only used once. I reject the idea that a custom input is an overhead, one of my projects has ~15 custom inputs. As a result, my views are much cleaner.
If simple_form provides a better fit for you and your project, use it. If you really think formtastic will value from this addition, fork it and send me a pull request. Get buy-in from the community instead of me, because I'm not motivated to add more noise into the views :)
Thanks for the explanation @justinfrench.