I want to set a default text_area value.
<%= f.text_area :observations, :value => partner_setting.observations, :class => "tinymce", :rows => 4, :cols => 120 %>
But the field displays the same default text after replacing the content and returning to edit.
How can I reset it after create?
Thanks!
If you want the text to persist on focus, try this instead:
<%= f.input :message, input_html: { value: 'hello hello'} %>
You will need a placeholder, otherwise it will erase your content.
<%= f.text_area :observations, :placeholder => partner_setting.observations, :class => "tinymce", :rows => 4, :cols => 120 %>
thanks for suggestions, I solved this issue through a helper method which takes 2 params (passing them from the view):
def offer_settings offer, key
offer.send(key) || offer.partner_setting.send(key)
end
view:
<%= f.text_area :offer_greeting, :value => offer_settings(#offer, :offer_greeting), :class => "tinymce", :rows => 4, :cols => 120 %>
Related
I am using a search box using the following form:
<div id='search-box'>
<%= form_tag "/search", :method => :get, :id => "search-form" do %>
<%= text_field_tag :q, params[:q], {:id => "search-text", :placeholder => "SEARCH FOR PRODUCTS"} %>
<%= submit_tag "Go" %>
<%end%>
</div>
The problem is that whenever I type something in the search box, it shows a dropdown with previous queries. I do not want to store the queries and show the dropdown. How can I purge the queries?
use autocomplete="off":
<%= text_field_tag :q, params[:q], {:id => "search-text", :placeholder => "SEARCH FOR PRODUCTS", :autocomplete => 'off'} %>
I have the following collection select which acts as a filter in a Rails app.
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, #doctors, :id, :full_name, {:include_blank => 'All'} %>
<% end %>
This always generates a name attribute of the select element like name="doctor[id]" which results in the browser to ?utf8=✓&doctor%5Bid%5D=1, which is not quite readable.
How can I change the name attribute to just name = "doctor" or basically just remove the brackets from it?
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select
The collection_select method contains the parameters "options" and "html_options". "options" allow you to add specific information, like {:include_blank => 'All'}, but does not replace html attributes.
You have to add the name to the next hash, like this:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, #doctors, :id, :full_name, {:include_blank => 'All'}, {:name => 'doctor'} %>
<% end %>
Have you tried:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, #doctors, :id, :full_name, {:include_blank => 'All', :name => 'doctor'} %>
<% end %>
I've got a form for selecting TIME. I'm using Simple Form and Jquery Timepicker. How do I remove the minute field of the form. So I have two fields for the :mondayopen parameter showing up. One is the hour and the other is the minute. How can I remove the minute.
Here's how it currently looks:
My Form
<%= simple_form_for [current_user, #store], :html => {:multipart => true, :class => 'form-horizontal'} do |f| %>
</br>
<%= f.input :mondayopen, :label => 'Monday Open Time', :input_html => { :class => 'mondayo' } %>
<%= f.button :submit, class: 'btn btn-primary', style: 'margin-left: 40px;' %><%= link_to 'Your Store', user_store_path(current_user, #store), :class => 'btn btn-inverse edit_store_button_path' %>
<% end %>
<script>
$('.mondayo').timepicker({ 'step': 15 });
$('.mondayc').timepicker({ 'step': 15 });
</script>
If you have mondayopen field as time type field SimpleForm creates time_select for you but you don't need it as you are using jquery timepicker plugin. So you can just redefine it like this:
<%= f.input :mondayopen, :as => :string, :label => 'Monday Open Time', :input_html => { :class => 'mondayo' } %>
I recently started testing web_app_theme plugin. In Create button I have something like this...
<button class="button" type="submit">
<%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%= t("web-app-theme.save", :default => "Save") %>
</button>
How can I add :disable_with => "Processing" to this button to prevent duplicate records?
I tried t("web-app-theme.save", :default => "Save"), :disable_with => "Processing", but of course, that didn't work.
You need to use form tag helper methods - something like this should do it:
<%= button_tag :class => "button", :type => "submit", :data => { :disable_with => "Processing" } do %>
<%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %>
<%= t("web-app-theme.save", :default => "Save") %>
<% end %>
Here's a link to the API docs for the button_to method: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to
Updated Dec 14, 2013 for Rails 3.2 & 4 syntax.
button_tag is entirely optional. You could just as easily edit the tag in html as follows:
<button class="button" type="submit" data-disable-with="Processing">
<%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%= t("web-app-theme.save", :default => "Save") %>
</button>
All that :disable_with does is add a data-disable-with attribute to the element. Then the jquery-rails gem's javascript (jquery_ujs.js) does the rest of the disabling work for you.
This is assuming, of course, that you're on rails 3.0 or higher.
I have this link:
<%= link_to "+1", video_votes_path( :video_id => video.id, :type => "up" ), :method => :post, :remote => true %>
but I want to turn its visual appearance to this: ⇑ with the HTML entity ⇑. How can I do this while keeping the link's functionality?
<%= link_to "⇑".html_safe, video_votes_path( :video_id => video.id, :type => "up" ), :method => :post, :remote => true %>