I have a Rails app and am using haml and bootstrap. One my form I have two fields for entering text, and only one is displayed, depending on a variable I set in the controller. If there is a text area I would like to size it, and the :rows attribute works but not columns.
I have also tried to use %div :class => 'span6' to widen the text_area, but it doesn't seem to work.
= form_for [#lesson_layout, #layout_field] do |f|
.field
= f.label :field_name
= f.text_field :field_name
- case #layout_type
- when "Text Field"
.field
= f.label :field_value
= f.text_field :field_value
- when "Text Area"
.field
= f.label :field_value_long
= f.text_area :field_value_long, :rows => 5, :placeholder => 'Enter text.'
.actions
= f.submit
EDIT
Tried the following code, and it did not change the size of the box.
.field
= f.label :field_value_long
= f.text_area :field_value_long, :rows => 5, :placeholder => 'Enter text using markdown.', :html => { :style => "width:300em" }
Something like this should work :
= f.text_area :field_value_long, :rows => 5, :class => "span6", :placeholder => 'Enter text.'
f.text_area(
:field_value_long,
:rows => 5,
:placeholder => 'Enter text.',
:html => { :style => "width:20em !important" }
)
OR
f.text_area(
:field_value_long,
:rows => 5,
:placeholder => 'Enter text.',
:html => { :class => "my_wide_class" }
)
Related
I'm upgrading rails version to rails6 then the error below occurred.
I don't know where to fix it.
Could anyone have any ideas please share with me...
ActionView::Template::Error (PG::UndefinedTable: ERROR: missing FROM-clause entry for table "company_groups"
LINE 1: SELECT "companies".* FROM "companies" WHERE (company_groups....
^
4: .control-group
5: = f.label :company_id, :class => 'control-label'
6: .controls
7: = f.collection_select :company_id, Company.user_companies, :id, :name
8: .control-group
9: = f.label :service_unit_id, :class => 'control-label'
10: .controls
app/views/admin/service_contracts/_form.html.haml:7
app/views/admin/service_contracts/_form.html.haml:2
app/views/admin/service_contracts/edit.html.haml:4
this is _form.html.haml
- action = (action_name == "new") ? "create" : "update"
= form_for #service_contract, url: {action: action},
:html => { :class => 'form-horizontal' } do |f|
.control-group
= f.label :company_id, :class => 'control-label'
.controls
= f.collection_select :company_id, Company.user_companies, :id, :name
.control-group
= f.label :service_unit_id, :class => 'control-label'
.controls
= f.collection_select :service_unit_id, ServiceUnit.all, :id, :name
.control-group
= f.label :active, :class => 'control-label'
.controls
= f.check_box :active, :class => 'check_box'
.control-group
= f.label :in_trial, :class => 'control-label'
.controls
= f.check_box :in_trial, :class => 'check_box'
.control-group
= f.label :price, :class => 'control-label'
.controls
= f.number_field :price, :class => 'number_field'
.control-group
= f.label :unlocked_on, :class => 'control-label'
.controls
= f.text_field :unlocked_on, type: 'date'
.control-group
= f.label :dealer_id, :class => 'control-label'
.controls
= f.collection_select :dealer_id, Company.dealers, :id, :name
.control-group
= f.label :description, :class => 'control-label'
.controls
= f.text_area :description, :class => 'text_area', rows: 4
.form-actions
= f.submit nil, :class => 'btn btn-primary'
= link_to t('.cancel', :default => t("helpers.links.cancel")),
admin_service_contracts_path, :class => 'btn'
I fixed another part witch had same error showed the problem clearly so I could figure it out like this below
Book.includes(calendar: :company).where("companies.id = ?", company).count
fix it to this↓↓↓↓↓↓↓↓↓↓
Book.includes(calendar: :company).where("companies.id = ?", company).references(:companies).count
thank you.
<label class="control-label">count</label>
<%= f.number_field :count, {:placeholder => "Count", :class => "multiple_text_field form-control", :required => true, :max=>"8",:min=>"8" } %>
If you want to have exactly 8 digits, the min value would be 10000000 and the max value would be 99999999.
Yes, you have done it almost. A little change to this:
<%= f.number_field :count, {:placeholder => "Count", :class => "multiple_text_field form-control", :required => true, max: 8, min: 8 } %>
<%= f.number_field :count, max: 10, min:4 %>
try this :
<%= f.text_field :title, class: "form-control", title: "Enter title length 50 characters", placeholder: "Enter Title", :required => true,:maxlength => 50, pattern: ".{1,50}" %>
I have a Rails form for which I'm trying to change the size of the default fields using either :size or both :cols => "30", :rows => "10" as in the code below. However, the form fields are staying the default size. Is there something I'm doing wrong?
<%= d.text_field c, :class => 'random', :value => "#{c}", :size => "30", :id => 'correction_data_'"#{c.parameterize}"%>
or this way
<%= d.text_field #title, :class => 'random', :value => "#{#title}", :cols => "30", :rows => "10", :id => 'correction_data_'"#{#title.parameterize}"%>
text_field doesn't consider rows and cols attributes, but does consider size attribute. text_area considers rows, cols and size attributes.
text_field:
<%= d.text_field c, :class => 'random', :value => "#{c}", :size => 30, :id => 'correction_data_'"#{c.parameterize}" %>
text_area using rows and cols:
<%= d.text_area #title, :class => 'random', :value => "#{#title}", :cols => 30, :rows => 10, :id => 'correction_data_'"#{#title.parameterize}" %>
text_area using size:
<%= d.text_area #title, :class => 'random', :value => "#{#title}", :size => "30x10", :id => 'correction_data_'"#{#title.parameterize}" %>
I have a form like so:
.row-fluid
= form_for(#client) do |f|
- if #client.errors.any?
#error_explanation
%h2
= pluralize(#client.errors.count, "error")
prohibited this client from being saved:
%ul
- #client.errors.full_messages.each do |msg|
%li= msg
.fieldset
%legend
= #header
.control-group
%label.control-label
Name
.controls
= f.text_field :name, :class => "input-xlarge"
.control-group
%label.control-label
Street Address
.controls
= f.text_field :street, :class => "input-xlarge"
.control-group
%label.control-label
Unit
.controls
= f.text_field :unit, :class => "input-small", :placeholder => "optional"
.control-group
%label.control-label
City
.controls
= f.text_field :city, :class => "input-xlarge"
.control-group
%label.control-label
State
.controls
= f.text_field :state, :class => "input-small"
.control-group
%label.control-label
Zip
.controls
= f.text_field :zip, :class => "input-small"
.form-actions
= f.submit "Save", :class => "btn btn-primary"
.btn
= link_to "Cancel", :root, :style => "color: #333; text-decoration: none;"
and I have a modal i'm loading up with the form inside like so:
.span2.offset2
%a.btn{"data-toggle" => "modal", :href => "#myModal", :role => "button"} New Client
/ Modal
#myModal.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
.modal-header
%button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
%h3#myModalLabel Modal header
.modal-body
%p
= render "form"
.modal-footer
%button.btn{"aria-hidden" => "true", "data-dismiss" => "modal"} Close
%button.btn.btn-primary Save changes
I'm wondering how to get the Save Changes button to submit the form. Do I need to add javascript to get it to work?
You need to make sure that the inputs and the buttons belong to one form element. This may be hard to achieve with your current markup.
Alternatively, you could submit the form with JavaScript, but the first method is much better, as you get a lot of functionality for free.
Suddenly my Rails application acts weirdly. If I attach an image on a edit page and submit the form, show action is called instead of update action. If I don't attach any image, it's ok.
Routes
namespace :admin do
resources :products do
collection do
get :download_images
get :all_styles
post :compress_images
end
end
end
View
%h1 Edit Product
= form_for [:admin, #product], :html => {:multipart => true} do |f|
- if f.object.accessory?
= render 'form_accessory', :f => f
- else
= render 'form', :f => f
[_form partial]
:javascript
function exclusiveCheck(check_box) {
if (check_box.checked) {
$('#pictures_fieldset .is_main').attr('checked', false);
check_box.checked = true;
}
}
- error_messages_for f.object
%fieldset.span-23
%legend
.row
= f.label :category_id, :class => "required"
%br
= f.select :category_id, array_of_categories('garment'), :include_blank => true
= f.check_box :new_in_category
= image_tag "new_icon.png"
.row
= f.label :style_no, :class => "required"
%br
= f.text_field :style_no, :style => "width: 5em;"
.row
= f.label :name, :class => "required"
%br
= f.text_field :name
.row
= f.label :fabric_info, :class => ""
%br
= f.text_field :fabric_info, :style => "width: 90%;"
.row
= f.label :lb_per_piece, "Weight", :class => "required"
%br
= f.text_field :lb_per_piece, :style => "width: 3em;"
.row
.span-3
= f.label :price, :class => "required"
%br
= f.text_field :price, :style => "width: 6em;"
.span-3
= f.label :original_price, :class => ""
%br
= f.text_field :original_price, :style => "width: 6em;"
.span-10
%label Discount Rate
%br
= text_field_tag :percent, nil, :style => "width: 3em;", :id => "percent"
= "%"
= link_to_function "Set", "setPrice();"
= f.check_box :new_in_sale
= image_tag "new_icon.png"
.row
= f.label :video, :class => ""
%br
= f.text_field :video, :style => "width: 15em;"
(Upload videos to data.ohyesfashion.com at ~/files/videos directory.)
.row
= f.label :available_on
%br
= f.text_field :available_on, :class => 'date'
.row
= f.check_box :active
= f.label :active, :class => ""
.row
= f.check_box :new_arrival
= f.label :new_arrival, :class => ""
= f.check_box :new_in_new_arrival?
= image_tag "new_icon.png"
.row
= f.check_box :best
= f.label :best, :class => ""
= f.check_box :new_in_best
= image_tag "new_icon.png"
.span-24.last
%button.button.positive(type="submit")
= icon_for(:accept, "Save")
%fieldset
%legend Sizes
- Product::SIZES.each do |size|
.span-2
= size.to_s.upcase
= f.select size, [*0..20].map { |i| i.to_s }
.span-24
.span-12
%fieldset
%legend Descriptions
- Description.order("code, name").each do |description|
.row
= check_box_tag "descriptions[]", description.id, f.object.descriptions.include?(description)
= "[#{description.code}]"
= description.name
.row
New Description
= text_field_tag :new_description_name
.span-12.last
%fieldset(style="float: right;")
%legend Colors
.span-11
- Color.order("name").each do |color|
.row
.span-1
= check_box_tag "colors[]", color.id, f.object.colors.include?(color)
.span-4
= color_box color
.span-3
= check_box_tag "sold_out_colors[]", color.id, (f.object.colors.include?(color) and Colorship.sold_out?(f.object, color))
Sold Out
.span-2
= check_box_tag "is_new_colors[]", color.id, (f.object.colors.include?(color) and Colorship.is_new?(f.object, color))
New
.span-24.last
%button.button.positive(type="submit")
= icon_for(:accept, "Save")
- (15 - f.object.pictures.size).times { f.object.pictures.build }
%fieldset#pictures_fieldset
%legend Images
.row
= f.label :model_id, "Model"
= f.select :model_id, PhotoModel.all.map { |i| [i.name, i.id] }, :include_blank => true
%br
= f.fields_for :pictures do |ff|
.span-7(style="height: 150px;")
- if ff.object.new_record?
= ff.file_field :image
- else
= image_tag ff.object.image.url(:w45)
%br
= ff.object.image_file_name
%br
= ff.check_box :is_main, :onclick => "exclusiveCheck(this)", :class => "is_main"
Title
%br
= ff.check_box "_destroy"
Delete
.span-24.last
= link_to icon_for(:back, "Back"), :back, :class => "button negative"
%button.button.positive(type="submit")
= icon_for(:accept, "Save")
:javascript
function setPrice() {
if ($('#product_original_price').val() != '' && $('#percent').val() != '') {
var originalPrice = parseFloat($('#product_original_price').val());
var percent = parseFloat($('#percent').val());
$('#product_price').val(originalPrice * (100 - percent) / 100.0);
}
}
Any idea what's going on? It used to work fine.