Skip to content

Suggestion: Ability to render input without label/li #861

Closed
elado opened this Issue Jun 15, 2012 · 6 comments

3 participants

@elado
elado commented Jun 15, 2012

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
  span twitter.com/
  = f.input_tag :username

What are your thoughts?

@elado
elado commented Jun 15, 2012

Just figured out I can use regular form functions (f.label, f.text_field etc.).
Closing.

@elado elado closed this Jun 15, 2012
@elado elado reopened this Jun 16, 2012
@elado
elado commented Jun 16, 2012

Reopening:

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.

@justinfrench
Owner

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.

@damien-roche

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?

@justinfrench
Owner

@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 :)

@damien-roche

Thanks for the explanation @justinfrench.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.