With simple_form_for, how should one go about building something like a color selector? Imagine a page where the user can pick a number of colors to work with by checking checkboxes. I would like to present a little box with the color in it and a checkbox next to it so the user can pick the color by checking the check box. Something like this
<input type="checkbox" name="colors[test]"><div style="background-color: red; width: 20px; height: 20px"></div>
<input type="checkbox" name="colors[test]"><div style="background-color: green; width: 20px; height: 20px""></div>
<input type="checkbox" name="colors[test]"><div style="background-color: blue; width: 20px; height: 20px""></div>
You can add the html tags to the collection and define classes for each of them. And then style them accordingly. I am assuming you have a simple_form_for #color or something similar.
<%= f.input :test, :label => 'Choose a Color:', :collection =>{'<div class="red colorbox"></div>'.html_safe => 'red', '<div class="green colorbox"></div>'.html_safe => 'green', '<div class="blue colorbox"></div>'.html_safe => 'blue' }, :as => :check_boxes %>
In your stylesheet:
/* The colorbox will be under a label with collection_check_boxes class.*/
.collection_check_boxes {
width: 30px;
height: 20px;
}
.colorbox {
width: 20px;
height: 20px;
}
.red {background: red;}
.green {background: green;}
.blue {background: blue;}
Related
I want to display my product image in a marker infowindow, but I get a broken link error:
qmxjai8cmuuve5mnpf4y.jpg:1
GET localhost:3000/v1503135294/qmxjai8cmuuve5mnpf4y.jpg 404 (Not Found)
I don't know how to include a cloudinary link in my infowindow.
My infowindow:
def gmaps4rails_infowindow(bien)
"
<div class='col-xs-6'>
<a href='#{user_path(product.user)}', class='btn btn-fill btn-danger btn-sm'>Accéder au profil</a>
</div>
<img src=\"#{product.user.photo.path}\" style='width: 200px; height: auto; margin: 10px; border-radius: 5px; text-align: center;'>
"
end
How I display it in my view:
<%= cl_image_tag user.photo.path, height: 100, width: 200 %>
Every cycle I get the new Thumbnail BUT under the previous one. Any suggestions how to solve that? How in each cycle add the new Thumbnail horizontally next to the previous one, until the space is fill and then move to the next line? Thanks.
From TO Picture
CODE
<% #employees.each do |em| %>
<div class="listTumbnail">
<% if em.user.imagepath %>
<div class = "user-image">
<img src="<%= em.user.imagepath%>" class="listimg">
</div>
<% else %>
<div>
<%= image_tag("icons/desconocido.jpg", :alt => "not found", :class => "listimg") %>
</div>
<% end %>
</div>
<% end %>
.user-image {
float: none;
padding-top: 127px;
margin-left: 193px;
padding-left: 6px;
border-left-style: solid;
border-left-color: #000;
border-left-width: 1px;
}
.listimg {
display: block;
max-width:80px;
max-height:100px;
width: auto;
height: auto;
margin: 0 auto;
border-radius: 40px;
}
.listTumbnail {
border: 2px solid #95989A;
border-radius: 3px;
color: #000;
height: 140px;
width: 110px;
margin: 5px;
}
try adding this to your stylesheet:
.listThumbnail {
display: block;
}
.user-image {
display: inline-block;
}
If for some reason you don't have a css file in your project, here's one basic way to add one:
Create a file named my_styles.css (or whatever you want to name it) & add the above css examples there.
Add the following link in the <head> of your application.html.erb file:
<link rel="stylesheet" type="text/css" href="my_styles.css">
This allows your html file to work with your css file/stylesheet.
I am using simple form simple_form (v: 3.2.1) with bootstrap in my current rails application( other developer previously worked on this project).
For creating radio button from collection I use
= f.input :default_ship,
label: 'foo)',
collection: default_ship_options(#company),
as: :radio_buttons
That generate html like
<span class="radio radio radio"><label for="foo"><input class="radio_buttons required" required="required" aria-required="true" type="radio" value="company" name="purchasing_source[default_ship]" id="foo"><span></span>Test Shipping Address</label></span>
Look at here an empty span <span></span> is created that actually for showing checkbox.
My CSS code:
.radio, .checkbox {
position: relative;
display: block;
margin-top: 10px;
margin-bottom: 10px;
}
.radio label, .checkbox label {
min-height: 20px;
padding-left: 20px;
margin-bottom: 0;
font-weight: normal;
cursor: pointer;
}
label input[type=checkbox], label input[type=radio] {
display: none;
}
label input[type=checkbox] + span, label input[type=radio] + span {
display: inline-block;
width: 1.4em;
height: 1.4em;
margin-right: 0.5em;
vertical-align: middle;
cursor: pointer;
border: 1px solid #AAA;
}
Now My problem is simple form does not create extra span for checkbox element that's why no check box is shown for checkbox. Generated Html for checkbox is
<span class="checkbox"><label for="manufacturer_currencies_fr"><input class="check_boxes optional" type="checkbox" value="fr" name="manufacturer[currencies][]" id="manufacturer_currencies_fr">Euro</label></span>
How can I generate extra span also for checkbox?
(I do not want to change my css because it already used many places)
It's seem to me that I have to do something at simple_form_bootstrap.rb but not sure. It can also be that previous developer may override some method but I have no idea where I can find that.
Here is an example of wrapping check_boxes. They are treated in the same way, so you can use 'options' parameter to pass the necessary data with key "collection_wrapper_tag". You can go into class "form_builder" of simple_form and find it by yourself.
= f.collection_check_boxes :tariffs, #form.tariffs, :first, :last, {checked: #form.selected_tariffs, collection_wrapper_tag: 'span'}
Best solution I found was to overwrite the label_input method on simple form's BooleanInput.
Add the boolean_input file in app/inputs/boolean_input.rb:
class BooleanInput < SimpleForm::Inputs::BooleanInput
def label_input(wrapper_options = nil)
if options[:label] == false || inline_label?
input(wrapper_options)
elsif nested_boolean_style?
html_options = label_html_options.dup
html_options[:class] ||= []
html_options[:class].push(boolean_label_class) if boolean_label_class
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
build_hidden_field_for_checkbox +
#builder.label(label_target, html_options) {
template.content_tag( :div, class: 'switch-checkbox') {
build_check_box_without_hidden_field(merged_input_options) +
content_tag(:span, '', class:'slider round')
} + label_text
}
else
input(wrapper_options) + label(wrapper_options)
end
end
end
Notice that I only added the sibbling span in case there is a label not inline and with nested_boolean_style? = true.
Most of the code in the method is copy pasted from the original in simple form.
I have a button below:
<table align="center" width="50%">
<tr>
<td style="color: #212121;">
<div class="button">
<%= button_to "Search", {:class => "buttonhome" } %>
</div>
</td>
</tr>
</table>
I am applying buttonhome class i.e below
.buttonhome
{
height: 100px;
width: 200px;
font-family: Arial;
background-color: transparent;
border-style: none;
font: white;
}
But its not applying on the button. Kindly suggest me. Waiting for reply. Thanks
<%= button_to "Search", {action: "search"}, {class: 'buttonhome'} %>
possible duplicate 1 2
Try
div.button .buttonhome
{
height: 100px;
width: 200px;
font-family: Arial;
background-color: transparent;
border-style: none;
font: white;
}
also check if your css is loading fine and your button has the class buttonhome.
The html_option is 3rd parameter of button_to according to documentation
http://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to
so use this
<%= button_to 'Search', {}, { :class => "buttonhome" } %>
I'm using Simple_Form with Zurb Foundation in my rails application.
One of more views has a form with the following date_select
The form fields are showing up stacked rather than inline. I've checked everything and can't figure out how to get these to show-up correctly.
What am I missing?
You can see the repo at https://github.com/stanrails/momtomom in the event.html.erb view.
The code for the section is below:
<div class="row">
<div class="small-5 columns">
<%= f.date_select :eventDate %>
</div>
</div>
One of the workaround is to have something manually like this:
form.custom .dropdown.date{
width: 30%;
margin-right: 10px;
float: left;
}
Here is another take on this I wanted to share which ends up looking like this:
A little html!
div[class="row"]
div[class="large-12 columns select-date-wrapper"]
= f.date_select(:birthdate,
options = { start_year: DateTime.now.year - 18, end_year: DateTime.now.year - 75, order: [:month, :day, :year], include_blank: true},
html_options = { class: 'select-date'})
A little sass!
select.select-date {
width: 30%;
margin-right: 10px;
float: left;
}
.select-date-wrapper{
select:first-of-type{
width: 45%;
}
select:nth-of-type(2){
width: 20%;
}
select:last-of-type{
margin-right: 0;
}
}
I solved the same problem by checking the html and changing the css of the relevant tags:
<%= f.date_select :date %> produces:
<div class="field col-md-6">
<select id="invoice_date_1i" name="invoice[date(1i)]">
<select id="invoice_date_2i" name="invoice[date(2i)]">
<select id="invoice_date_3i" name="invoice[date(3i)]">
</div>
With "Invoice" being the model name here. Therefore, in your css you can add
#yourModel_date_1i, #yourmodel_date_2i, #yourmodel_date_3i { width: 30%; }
for an easy fix.