Trying to get bootstrap placeholder to show up in text input box
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hi, I'm trying to get a placeholder of 3000, 13.17, 12, and Dec 1, 2013 to show up on notes#new

I've tried adding various snippets to this branch (it uses simple_form gem)

The snippets I've tried are ones likes like input_html: {class: "input-medium", placeholder: "13.17" } and data: { placeholder: "13.17" } but none of them seem to work.

awarded to alixaxel

Crowdsource coding tasks.

2 Solutions


You should put the placeholder attribute outside "input_html":

<%= f.input :amount, label: "Loan Amount ($)", input_html: {class: "input-medium"}, placeholder: "3000" %>
@weslley yeah I tried that, but nothing. Here are 2 screenshots : http://imgur.com/OeItc8V,kyfltdI#0 http://imgur.com/OeItc8V,kyfltdI#1
akshatpradhan over 5 years ago
@akshatpradhan: Is the wrapper supposed to have 2 colons after?
alixaxel over 5 years ago
yeah, the 2 colons is the new hash syntax for ruby 1.9. A hash is a collection of unique keys and their values, kind of like associate arrays in your PHP world I believe.
akshatpradhan over 5 years ago
@akshatpradhan Have you tried adding b.use :html5 and b.use :placeholder to the input wrapper config? https://github.com/plataformatec/simple_form#the-wrappers-api
weslly over 5 years ago
@akshatpradhan: Ah! I see, good to know. =)
alixaxel over 5 years ago
@alixaxel actually its helpful for my rails memory to write those answers out loud to you, so please do ask more!
akshatpradhan over 5 years ago
@weslly From simple form bootstrap rb and simple form rb it looks like the b.use is already set in the initializers.
akshatpradhan over 5 years ago
@akshatpradhan: Yeah, those seem to be the default options. And even with html5 off, the placeholder would still hold according to their docs. Have you tried a barebone example to see if the culprit lies in the other options? I mean without wrapper, classes, addons and so on - just id and the placeholder?
alixaxel over 5 years ago
@alixaxel Would that actually work?
akshatpradhan over 5 years ago
@akshatpradhan: My guess, probably not. But with a minimal example you would be able to know for sure if this is a syntax problem or not. Just try to output <%= f.input :email, placeholder: 'user@domain.com' %>, if it still doesn't work I would dig deeper on the documentation.
alixaxel over 5 years ago
@akshatpradhan: isn't the correct syntax <%= f.input :email, :placeholder => "user@domain.com" %>?
weslly over 5 years ago
@weslly :symbol => "string" is now the same as symbol: "string" https://github.com/plataformatec/simple_form#usage
akshatpradhan over 5 years ago
@alixaxel the output of work's perfectly fine as can be seen on this page and seen in the code
akshatpradhan over 5 years ago
@akshatpradhan: Cool. So, what happens if you change the order of placeholder so it comes before input_html? From what I remember reading, the single/double quotes don't matter. Another thing, shouldn't the placeholder be defined in the f.input_field line as opposed to the f.input one?
alixaxel over 5 years ago
Wow, order matters, and I don't get why. Your suggestion worked: code, screenshot
akshatpradhan over 5 years ago
@akshatpradhan: I would have to know more about Ruby and dwelve into the code to understand why, but I'm glad it worked! =) Perhaps @weslly can shed some light on why the order matters?
alixaxel over 5 years ago
@akshatpradhan: Might it be due to the presence of input_html too? Something like if input_html exists then use that, else build the attributes? That would make some sense as well.
alixaxel over 5 years ago
Yeah if @weslly would be able to chime in, that would be great. I'm really interested. I'll tip if you have time to find the answer!
akshatpradhan over 5 years ago
@akshatpradhan: I'm heading out to watch Portugal v Sweden, but if by the time I get back you still don't know, sure - I'll look into it. =)
alixaxel over 5 years ago
@akshatpradhan I'll take a look, it's already a long time since I last used ruby/rails and when I did I used the formhelper :)
weslly over 5 years ago
@akshatpradhan: Just to let you know that I swept through the code and couldn't find anything to justify that. =|
alixaxel over 5 years ago
@alixaxel thank you again btw!
akshatpradhan over 5 years ago
@akshatpradhan: You're welcome! And thanks for the tip. =)
alixaxel over 5 years ago
@alixaxel I was wondering if you'd be able to look at my new bounty and opine if possible!
akshatpradhan over 5 years ago
@akshatpradhan: I'm very, very, very sleepy atm. :P I'll do it tomorrow. Q: What happens if the lender "pays" and then the borrower refuses the loan? Shouldn't there be a step in betweeen? Or are there other mechanisms in place?
alixaxel over 5 years ago
@akshatpradhan thanks for the tip :), I still didn't find the motive to the order error, though
weslly over 5 years ago
Winning solution

I think I found the culprit (at least partially).

Simple Form also allows you to use label, hint, input_field, error and full_error helpers. Any extra option passed to these methods will be rendered as html option.

The placeholder option should work fine with the input helper:

<%= f.input :email, placeholder: 'user@domain.com' %>

For input_field, apparently you need simple_form >= 2.1.0 and then the syntax should be the same.

View Timeline