How can I put arbitrary content between the label and input tag? #237

Closed
jeroenhouben opened this Issue Apr 19, 2011 · 12 comments

Comments

Projects
None yet
4 participants
Contributor

jeroenhouben commented Apr 19, 2011

Question: I'd like to call a method that only renders the INPUT tag, nothing else, just like you're able to just render the label or hint.

Reason I'd like to do this is to be able to add a euro or dollar sybmol in front of an input:

<div class="input numeric integer optional field_with_errors">
    <label class="integer optional">Amount</label>
    &euro;
    <input class="numeric integer optional" type="number" value="bla" step="1" size="5" min="5">
    <span class="hint">bla bla</span>
    <span class="error">is not a number</span>
</div>

The following almost works, but seems to use the builtin Rails helpers, and not simple_form with its cool classes and inferred attributes (step, min etc..)

<%= f.input :amount do %>
    &euro; <%= f.number_field :amount %>
<% end %>

Any ideas?

Thanks a lot

Collaborator

carlosantoniodasilva commented Apr 19, 2011

I can just think on the block way for now. You should be able to use f.input again inside the block, by giving false to the options you don't want:

<%= f.input :amount do %>
    &euro; <%= f.input :amount, :label => false, :hint => false, :wrapper => false %>
<% end %>

Another question: can't the euro sign be inside the label? Is there any issue doing it this way?
I'll ask you to please use the mailing list for questions, there are more people there to help you and you might end up helping others :). Thanks.

Owner

josevalim commented Apr 19, 2011

I think we could allow people to generate just the input. At first it didn't make sense, but today our inputs have a lot of logic, somaybe we could have simple_input or something like that. what do you think Carlos?

josevalim reopened this Apr 19, 2011

Contributor

jeroenhouben commented Apr 19, 2011

Your suggestion works fine, sure it could be a little cleaner, but it works:

<%= f.input :min_eligable_amount do %>
    <span class="currency">&euro;</span> <%= f.input :min_eligable_amount, :label => false, :hint => false, :wrapper => false, :error => false  %>
<% end %>
Contributor

jeroenhouben commented Apr 19, 2011

Oh and to answer your question. No, I think semantically it's not part of the label, and this gives more options for styling too.

Collaborator

carlosantoniodasilva commented Apr 19, 2011

@jeroenhouben I think it's possible to make it cleaner with the :components option (I didn't remember about it before):

<%= f.input :min_eligable_amount do %>
    <span class="currency">&euro;</span> <%= f.input :min_eligable_amount, :components => [:input]  %>
<% end %>

Please give it a try.

@josevalim maybe it's a good option to have this out of the box, although I think it would be basically the f.input call above. So, is it really necessary, or should we just add it as an example, since it's not a usual case?

Owner

josevalim commented Apr 19, 2011

Yeah, having something like raw/simple_input would be perfect in your case.

Owner

josevalim commented Apr 19, 2011

@josevalim maybe it's a good option to have this out of the box, although I think it would be basically the f.input call above. So, is it really necessary, or should we just add it as an example, since it's not a usual case?

IMHO it would be a nice shortcut, but that is up to you. :)

Contributor

jeroenhouben commented Apr 19, 2011

Yes, almost ;-)
Needed to add :wrapper => false

<%= f.input :min_eligable_amount do %>
  <span class="currency">&euro;</span> <%= f.input :min_eligable_amount, :components => [:input], :wrapper => false  %>
<% end %>
Collaborator

carlosantoniodasilva commented Apr 19, 2011

@jeroenhouben ah nice.
So I agree it's a good shortcut to have. Lets leave the issue here to implement this feature. Meanwhile, perhaps you could try out a patch and send us a pull request, what do you think? Thanks.

Contributor

jeroenhouben commented Apr 19, 2011

I've sent a pull request

Collaborator

carlosantoniodasilva commented Apr 19, 2011

Nice, I'll review and apply it later. Thanks.

On Tue, Apr 19, 2011 at 1:14 PM, jeroenhouben <
reply@reply.github.com>wrote:

I've sent a pull request

Reply to this email directly or view it on GitHub:
#237 (comment)

At.
Carlos A. da Silva

Collaborator

rafaelfranca commented Apr 19, 2011

The pull request was applied. I also renamed the method for input_field.

Thanks mates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment