Hi i'm trying to change the following:
.form-group
= label_tag :metric, 'Metric', class: 'sr-only'
= select_tag :metric, options_for_select(Report::METRICS, selected: #report.metric), class: 'form-control'
to something like the following:
.form-group.pull-left
= label_tag :metric, 'Metric', class: 'sr-only'
.btn-group{"data-toggle" => "buttons"}
%label.btn.btn-default.active
%input#option1{name: "options", type: "radio", value: "value1"}/
Value1
%label.btn.btn-default
%input#option2{name: "options", type: "radio", value: "value2"}/
Value2
However the problem is that when I submit the form, it doesn't actually submit the radio button value. Also after it submits, it defaults back to no selection when it should remain on the selected radio button.
You can use the radio_button_tag helper and set the checked parameter correctly.
Using your example, it's something like this:
.form-group.pull-left
= label_tag :metric, 'Metric', class: 'sr-only'
.btn-group{"data-toggle" => "buttons"}
%label.btn.btn-default.active
= radio_button_tag('options', 'value1', params[:options] == 'value1')
Value1
%label.btn.btn-default
= radio_button_tag('options', 'value2', params[:options] == 'value2')
Value2
Related
I am trying to change date format for date_field_tag, but i am not getting proper.
code i have used:
<%= date_field_tag 'dob' , '' , value: #search_params[:dob], placeholder: 'YYYY/MM/DD', autocomplete: 'off', class: 'form-control' %>
i need to display format and save yyyy/mm/dd
<%= date_field_tag 'dob', #search_params[:dob].to_date.strftime("%Y/%m/%d"), placeholder: 'YYYY/MM/DD' %>
Note that date_field_tag method signature helper's signature is date_field_tag(name, value = nil, options = {})
I have a view for editing my model. I am using Slim views.
My model_name is 'cupcake'
= simple_form_for [:admin, :order, record] do |f|
.row
.col-md-6
label for="_kind" Kind
= f.select :kind, [['Clipart', :clipart], ['Image', :image], ['Message', :message]], { selected: record[:kind] }, value: record[:kind], class: 'form-control', :input_html => { :name => "cupcake[:kind]" }
- if #record[:kind] == 'image'
.col-xs-12
= f.input :image, as: :shrine_file
- elsif #record[:kind] == 'clipart'
.col-md-6
label for="_clipart" Clipart
= f.select :clipart_id, options_for_select(#cliparts.map { |c| [c['name'], c['id'], {'value' => c['id']}] }, selected_key = selected_clipart(record).id), { selected: selected_clipart(record).name }, class: 'form-control', :input_html => { :name => "cupcake[:clipart_id]" }
- else
.col-md-6
= f.input :text_line_style, collection: ["Three Line Text","Single Line Text"], checked: record['first_line'] ? 'Three Line Text' : "Single Line Text", as: :radio_buttons, item_wrapper_class: "inline"
.row
.col-xs-12
hr
button.btn.btn-success.btn-lg
= fa_icon('check')
| Save
- redirect_location = [:admin, :cliparts]
= link_to redirect_location, class: 'btn btn-primary btn-lg'
= fa_icon('chevron-left')
| Back
.col-xs-12
- if f.object.created_at.present?
p.help-block Created at: #{f.object.created_at}
- if f.object.updated_at.present?
p.help-block Updated at: #{f.object.updated_at}
I want to update the view based on the kind selected. Currently, it is not updating the view if I select a different kind. When I try to access cupcake[:kind], it is showing undefined error. Any way to access the cupcake object? I looked for it in the f object. But, I couldn't find it.
Anyone, please help?
I am using Rails, HAML and simple_form and I am attempting to create a select with an option to enter text if the item is not found in the collection. Is this possible? It currently looks like this:
= simple_form_for [:admin, office] do |f|
= f.input :person,
label: "Select Person",
collection: People.all,
label_method: -> (person) { person.name },
input_html: { data: { plugin: "select2" } }
= f.submit "Set Person", class: "btn btn-primary btn-block"
I'm working with Javascript only for a couple of months, and am stuck with this issue. I have a page with 2 modals, which contains a JQuery-UI-Datepicker. First modal creates an entry with start date, and the second modal allows making changes to this entry.
First modal works perfectly. When I try to change the date in the second modal, nothing happens. I can select a month, a year, but when I select a date, the calendar form disappears, and the value is not changed.
I assumed that the datepicker hide behind the modal as here,
but the solution didn't work out for me. The second assumption was like in this question but it wasn't helpful for me either.
Here's the code I work with (I didn't write it myself):
$(document).on("click",".datepicker",function() {
var first_datepicker = $(".datepicker:first");
if($(this) !== first_datepicker || $(this).datepicker('getDate') == null) {
$(this).datepicker('setDate',first_datepicker.datepicker('getDate'));
}
});
// First modal
.modal.fade{id: "create_ea_bahncard", role: "dialog", tabindex: "-1"}
.modal-dialog{role: "document"}
.modal-content
= semantic_form_for #ea_bahncard,url: finance_ea_bahncards_path(person_id: person),html_options: {method: :post} do |f|
= f.input :person_id, as: :hidden
.modal-header
.row
.col-md-10
%h2
Neue Bahncard
.col-md-2
%button.close{type: :button, data: {dismiss: 'modal'}, aria: {hidden: 'true'}}
%i.fa.fa-times-circle
.modal-body
.row
.col-md-5
= f.input :bahncard_type, as: 'string', label: "Bahncard-Typ", input_html: {class: "form-control"}
= f.input :valid_until, as: 'bs_jquerydate', label: "Gültig bis", input_html: {class: "form-control"}
.col-md-5
= f.input :total_amount, as: 'string', label: "Voller Betrag", input_html: {class: "form-control"}
.modal-footer
= submit_tag 'Speichern', class: 'btn btn-default btn-primary'
%button.btn{data: {dismiss: 'modal'}} Abbrechen
// Second modal
.modal.fade{id: "ea_bahncard_#{bc.id}"}
= semantic_form_for bc,url: finance_ea_bahncard_path(bc),html_options: {method: :put} do |f|
= f.input :person_id, as: :hidden
.modal-header
.row
.col-md-10
%h2
Bahncard bearbeiten
.col-md-2
%button.close{type: :button, data: {dismiss: 'modal'}, aria: {hidden: 'true'}}
%i.fa.fa-times-circle
.modal-body
.row
.col-md-5
= f.input :request_date, as: 'string', label: "Antragsdatum", input_html: {class: "form-control"}
= f.input :bahncard_type, as: 'string', label: "Bahncard-Typ", input_html: {class: "form-control"}
= f.input :valid_until, as: 'bs_jquerydate', label: "Gültig bis", input_html: {class: "form-control"}
.col-md-5
= f.input :proportional_amount, as: 'string', label: "Anteiliger Betrag", input_html: {class: "form-control"}
= f.input :total_amount, as: 'string', label: "Voller Betrag", input_html: {class: "form-control"}
.modal-footer
= submit_tag 'Speichern', class: 'btn btn-default btn-primary'
%button.btn{data: {dismiss: 'modal'}} Abbrechen
I have the idea of selecting only the second modal for the function, but didn't implement it yet.
Can you please share you ideas of what to do?
After a couple of days I found a solution.
First, it turned out that there were several input fields and the code was written the way it chose only the first input field. That is the reason other fields did not respond.
For solving that i added a selected class to the clicked element.
Second, the selected input field had the same id as the a class above it. This question was a great help. I changed the id and it worked.
The function now looks like this:
$(document).delegate(".datepicker", 'click', function() {
$('.datepicker').removeClass('selected');
$(this).addClass('selected');
$(this).datepicker({dateFormat: 'dd-mm-yy'});
$(this).datepicker('setDate', new Date($(this).val()));
});
.modal-body
.row
.col-md-3
= f.input :requested_at, as: 'bs_jquerydate', label: "Eingangsdatum", input_html: {class: "date", id: "input_edit_request_#{request.id}"}
.modal-body
.row
.col-md-5
= f.input :valid_until, as: 'bs_jquerydate', label: "Gültig bis", input_html: {class: "form-control", id: "input_ea_bahncard_#{bc.id}"}
Hope this helps others.
When I create a new answer of a Poll, I need to increase the value by one of a hidden_field :sequence . What do I need to add in the value in hidden_field?
.poll_row
.poll_item
= f.input :answer, input_html: { class: 'ctrlenter expanding' }, label: false, placeholder: 'Введите вариант ответа'
= f.hidden_field, :sequence, value:??????
= button_tag 'вверх', type: 'button', class: 'up_id', value: 'up'
= button_tag 'вниз', type: 'button', class: 'down_id', value: 'down'
- if #poll.editable?(current_user)
= link_to_remove_association "remove", f, { wrapper_class: 'poll_item' }