How to insert hint information right after the input box? - ruby-on-rails

Not really an issue but some question that I need
Is it possible to attached html values right after the input box? Something like a small text info below the input box
I have did something similar but its not pretty.
f.inputs "Blog" do
f.input :view_counts, :input_html => { :readonly => true }
f.input :slug
li raw("<label class='label'> </label><span class='text-info'>Your Slug will be automatically based on your title or you can choose to enter your own slug title</span>")
f.input :title
f.input :content, :as => :ckeditor
f.input :is_active
f.input :admin_user_id, as: :hidden, :input_html => { :value => current_admin_user.id }
end
The code is between :slug and :title. You will catch a draft of what I am trying to do. Thanks

you can add a label like:
<label for="slug" class="hint">Your Slug will be automatically based on your title or you can choose to enter your own slug title</label>
Then add css styling something like:
.hint {
font-weight: normal;
color: #777;
font-size: .85em;
}

Thanks for the help, I found the way to do it.
f.input :slug, hint:"love u"
This will add a small cursive text just below the input box.

Related

Rails unable to change label in formtastic

Hi I'm new to rails and formtastic.
I've built a working solution for multiple file uploads using paperclip.
In my form, when I try and change the label of the upload file it still displays 'image' even when changing to:
<%= f.inputs :image, :label => false, :for => :attachments, :as => :file %>
or
<%= f.inputs :image, :label => "This label will not display", :for => :attachments, :as => :file %>
really silly problem but any help would be appreciated
thanks
f.inputs does not support label attribute, you should use f.input if you want hide label. Or you can bypass this and hide label via css. Something like this.
label[for=here_go_your_for_value] {
display: none;
}

Ruby on Rails simple_form prepend $ before input with custom label

I'm trying to prepend a $ in front of one of my fields and I was able to successfully do so, but without a custom label. This is the code that works:
= f.input :amount do
$
= f.input_field :amount, :label => false, :hint => false, :wrapper => false
This leads me to two confusing points. 1) Why does a label still appear when :label => false? and 2) why does this fail if I change it to:
= f.input :amount do
$
= f.input_field :amount, label: 'This is my label', :hint => false, :wrapper => false
When I change the label to my custom label the $ moves above the label instead of in front of the field. All help is appreciated, thanks.
when you are doing
= f.input :amount do
$
= f.input_field :amount, label: 'This is my label', :hint => false, :wrapper => false
This generates html
$
<label for="amount">This is my label</label>
<input id="amount" name=" " type="text" />
I'm not sure but i think simple_form is applying a css of display:block on your labels as from here labels are inline elements
I think all you need is some css magic to fix your issue
= f.input :amount do
= f.input_field :amount, label: 'This is my label', :hint => false, :wrapper => false
%span.dollar $
and then on your input field use this css:
#input_id{
//here your input_id would be something like resource_amount you can check it in developer console to be sure
display:inline-block;
}
.dollar{
float: left;
}
JSFiddle

Semantic ui with simple_form

tell me how to configure simple_form. I would like to use the checkbox of semantic ui, but when I wrap checkbox in the class, he becomes active, that is, visually it is, but when you click the check box is not activated.
= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
.ui.three.column.middle.aligned.relaxed.grid.basic.segment
.column
.column
.column
.ui.form.segment
#marg.field= f.label :email, 'Email'
#marg.field=f.input :email, placeholder: 'Email', autofocus: true, label: false
#marg.field= f.label :password, 'Пароль'
= f.input :password, :required => false, placeholder: 'Пароль', label: false
#marg.ui.toggle.checkbox
= f.input :remember_me, as: :boolean if devise_mapping.rememberable?
#marg= f.button :submit, 'Войти!', class: 'small ui blue submit button'
http://i.imgur.com/C8Wn4K9.png
Please try it
= f.input :remember_me, as: :boolean, boolean_style: :inline
A simpler way to do this is to create a custom simple form wrapper. Here is a blogpost which describes how to add the wrapper: http://pranavsingh.me/semantic-ui-simple-form-wrapper/
The above configuration will automatically add all the essential classes semantic form classes, and also adds wrappers to create proper checkbox fields. Below is an example:
= f.input :published, label: "Published?",
hint: "If you are not ready to go live yet, keep this site unpublished.",
wrapper: :ui_toggle_checkbox
Here's what I had to do (the accepted answer got me on the right track, but didn't fully fix the issue):
In the config/initializers/simple_form.rb file, change
config.boolean_style = :nested
to
config.boolean_style = :inline
This prevents Simple Form from wrapping the input tag in the label tag (essentially inserting a tag between the '.ui .checkbox' div and the input, which breaks Semantic's checkbox functionality).
In the app/assets/javascripts/application.js file:
$('.ui.checkbox').find('input').checkbox();
My form now displays checkboxes correctly and passes the appropriate value when submitted.
Here is another option (to just fix one checkbox) -
In a _form.html.erb partial:
<div class="inline field">
<div class="ui checkbox">
<%= my_form.input :my_input, label: 'My Label', as: :boolean, boolean_style: :inline %>
</div>
</div>
In the application.js file:
$('.ui.checkbox').find('input').checkbox();

Rails simple_form label for select

I'm trying to set a label for the following line but I keep getting an error if I add label_method anywhere. label: is just ignored. How can I add a label for f.select?
<%= f.select :state_identifier, Location::STATE, { prompt: 'State', id: 'state' } %>
I tried the following but it doesn't format properly in form-horizontal, leaving no gap between the label and data.
<%= f.label :state_identifier, label: 'State' %>
This is because f.select is not a simple_form method and does not support :label
Something like this should work for you w/ simple form.
<%= f.input :state_identifier, :label => "State", :collection => ["a","b"], :input_html => {:id=>"state" } %>
Hope this helps.

How to make the body textarea of form pre filled in Rails?

I have a simple form
<div class="form-inputs">
<%= f.input :title %>
<%= f.input :body %>
</div>
now I want the textarea to be already pre filled with some text (preferably html), how to do it ?
Thanks
You just want a value to be filled in then use this:
<div class="form-inputs">
<%= f.input :title, :input_html => { :value => "This is title field value." } %>
<%= f.input :body, :input_html => { :value => "This is body field value." } %>
</div>
There is too few details in your question. There is an option for input method to specify a value. But I'd say it is not very good practice.
The good practice would be:
for existing record show what it has in body: it already works
for a new record, if you want default body text, you'd better specify it on creation
#rec = Record.new(:body => "default text")

Resources