I have the code:
<% generate_bullets = Bullet.all %>
<% generate_bullets.shuffle.first(4).each do |t| %>
<%= f.text_field, :bullets, :class => 'text_field disabled' %>
I want to disable a text box using embedded ruby, and am unable to do so. If I could receive any help on the situation I'm facing, it would be very greatly appreciated.
After I disable the text box I want to have a button generate four random ID's from the database table "bullets" and print them on the disabled text box in an array format, and utilize those four printed ID's to post them onto a created page. Any help with that would be even better.
Let me know if I'm reading this right: you're trying to disable the text field from the get-go in the HTML. Is that right?
If so, disabled isn't a class; it's its own attribute.
<%= f.text_field, :bullets, :class => 'text_field', :disabled => true %>
You can also use :readonly => true attribute.
For HAML
= f.text_field :name, :class => "form-control", :readonly => true
For ERB
<%= f.text_field :name, :class => "form-control", :readonly => true %>
Related
I'm using simple_form in Rails 4, and I was using an input that I then passed data attributes to like so:
<%= f.input :url, :input_html => {"data-toggle" => "tooltip", :title => "My tooltip"} %>
and it worked as expected, creating tags like:
<input data-toggle="tooltip" data-original-title="My tooltip">
Now, however, I need to use simple_form's input_field so I can have more control over the display, but it doesn't seem to accept the input_html argument. My code looks like:
<%= f.input_field :url, :input_html => {"data-toggle" => "tooltip", :title => "My tooltip"} %>
and it results in:
<input html="{:data=>{"data-toggle"=>"tooltip", :title=>"My tooltip"}}">
Which is clearly suboptimal (I stripped other irrelevant properties and attributes to simplify). Any ideas on how to make this work?
Looking at the code for SimpleForm::FormBuilder#input_field, it appears that all options passed in are treated as if they were under :input_html.
Try removing :input_html and just passing the options directly:
<%= f.input_field :url, "data-toggle" => "tooltip", :title => "My tooltip" %>
I'm newbie and I'm developing an app with rails and bootstrap. I'm using this to generate a field on a form:
<%= d.text_field :email, :placeholder => "email" %>
<%= text_field_tag 'doctor[name][]', nil, :placeholder => "name" %>
and it works perfectly but I want to resize the height of it. I googled and I didn't found any good answer that fits.
Does anyone faced this issue?
If you're using bootstrap v2, you should add this:
<%= d.text_field :email, :placeholder => "email", :class => "span5" %>
Note that the number in span class is referred to the size that you want to put.
If you're using this new bootstrap (v3 rc), you should check this page
This line is in one of my forms:
<%= question.answer %><%= f.text_field :answer, :placeholder => "Respond..." %>
It displays the answer to a question and shows a text field to update that answer.
The only problem is that the place holder text is never shown and the content is always set to the answer content rather than "Respond..." as a placeholder.
Try this:
<%= question.answer %><%= f.text_field :answer, '', :placeholder => "Respond..." %>
You were setting your placeholder as the value parameter: text_field_tag(name, value = nil, options = {})
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag
<%= question.answer %><%= f.text_field :answer, :value => "", :placeholder => "Respond..." %>
Does the trick it seems, this is a modified version of #Yogzzz's answer - he should get credit. He hasn't made the changes to his answer so I can't accept it as correct.
Using Rails 3 with Twitter Bootstrap and Simple_form, I am having issues changing the length of the input box in this field:
<div class="input-prepend input-append">
<%= f.input :price, :wrapper => :append do %>
<span class="add-on">$</span>
<%= f.input_field :price %>
<span class="add-on">.00</span>
<% end %>
</div>
Others say to add this after the :price variable:
:input_html => {:size => 15}
The 'do' loop seems to change the rules, any suggestions?
try
:style => "width: 100px;"
Twitter bootstrap has css classes for this. Depending on what size you want you can add class input-min, input-small, input-large and so on. You can also use the span classes, e.g. span1, span2, etc.
<div class="input-prepend input-append">
<%= f.input :price, :wrapper => :append do %>
<span class="add-on">$</span>
<%= f.input_field :price, :class => 'input-medium' %>
<span class="add-on">.00</span>
<% end %>
</div>
I am using the f.input form to create controls with labels in a :class => 'form-horizontal' form, using a class attribute or style attribute (directly or as a hash, any way I tried) didn't work for me, and had zero effect on the generated HTML.
This is what worked for me:
<%= f.input :description, input_html: { class: 'span12' } %>
This works with both the Bootstrap column layout classes ('span1', 'span2', etc,) the input sizing classes ('input-large', 'input-xxlarge', etc,) or whatever custom class you want. The trick is using the input_html key. You can also mess with the label using the label_html key but that's likely to mess up the form-horizontal layout.
It looks like the size key in :input_html => {**:size** => 15} is ignored by SimpleForm... when I tired this it did not affect the HTML output.
I found this here in the SimpleForm docs:
https://github.com/plataformatec/simple_form#usage
I'm using simple form for a basic login form for my site within the nav area at the top of the page.
Currently, it's spilling the form fields over two rows and no matter how many display: inline attributes I apply. It still refuses to go back onto one line.
What im trying to do is restrict the number of characters in the form so that the fields fit onto one line.
Here's my current form code..
<%= simple_form_for("user", :url => user_session_path, :html => {:id => "sign_in", :class => 'form-inline' }, :remote => true, :format => :json) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.submit 'Login' %>
<%= link_to "Forgot your password?", new_password_path('user') %>
<% end %>
Easy way is to simply use the maxlength html attribute for inputs:
f.input :name, :input_html => { :maxlength => x }
But that will just restrict the number of characters that can be added into a single input. If your problem is with the width of those inputs, just use CSS to specify a custom width per input so the inputs won't overflow into a second line.