I am trying to connect my form.date_select to my stimulusjs controller but I can't do it.
I have the following code
= f.date_select :date_of_birth, :order => [:day, :month, :year], selected: Date.today, prompt: { day: 'Select day', month: 'Select month', year: 'Select year' }, start_year: Date.current.year, end_year:Date.current.year - 100, data: {signupform_target: 'dateOfBirth', action: 'signupform#isValidDob' }
I am trying to connect this to dateOfBirth target. my controller:
export default class extends Controller {
static targets = ['firstName', 'firstNameInput', 'lastName', 'lastNameInput', 'email', 'emailInput',
'password', 'passwordInput', 'dateOfBirth', 'dateOfBirthInput', 'button', 'warning']
isValidDob() {
console.log(this.dateOfBirthTarget);
}
This is the error I get.
[1]: https://i.stack.imgur.com/6Z7Jz.png
This is my form
= form_for(#user, url: settings_public_path(locale: I18n.locale, id: #user),
data: { controller: "generalsettings" }) do |f|
.field.pb-4
= f.label t('sign_in.your_email')
= f.text_field :email, class: 'form-control field-text-input settings-input', disabled: 'disabled'
%div{style: 'font-size: .9rem !important;'}
=t('settings.cant_change_email')
.names-flex.pb-4
.name-div.first-name
= f.label t('sign_up.fname')
= f.text_field :first_name, class: 'form-control field-text-input settings-input', disabled: #user.provider.present?, data: { generalsettings_target: 'firstName', action: 'generalsettings#isValidCombination'}
.name-div.last-name
= f.label t('sign_up.lname')
= f.text_field :last_name, class: 'form-control field-text-input settings-input', disabled: #user.provider.present?, data: { generalsettings_target: 'lastName', action: 'generalsettings#isValidCombination'}
.field.pb-4
= f.label t('sign_up.dob')
.dob-picker
= f.date_select :date_of_birth, :order => [:day, :month, :year], prompt: { day: 'Select day', month: 'Select month', year: 'Select year' }, start_year: Date.current.year, end_year:Date.current.year - 100, disabled: #user.provider.present?, data: { generalsettings_target: 'dateOfBirth', action: 'generalsettings#isValidCombination'}
= f.submit t('settings.save'), class: 'sign-button save_button', data: { generalsettings_target: 'button'}
Related
Here is code for date selector in my rails form-
<div class="field columns large-3">
<%= form.label :planned_start_date, :class=>"required" %>
<%= form.date_select :planned_start_date, start_year: #project_start_year, end_year: #project_end_year, :include_blank => true, order: [:day, :month, :year], class: 'select-date' %>
</div>
<div class="field columns large-3">
<%= form.label :planned_end_date, :class=>"required" %>
<%= form.date_select :planned_end_date, start_year: #project_start_year, end_year: #project_end_year, :include_blank => true, order: [:day, :month, :year], class: 'select-date' %>
</div>
</div>
I want to add dd mm yyyy instead of null selector by default. How can i change that?
As mentioned in ruby doc for date_select
= form.date_select :planned_end_date, start_year: #project_start_year, end_year: #project_end_year, :include_blank => true, order: [:day, :month, :year], prompt: { day: 'dd', month: 'mm', year: 'yyyy' }, class: 'select-date'
Hello I am trying to make a date_select and the class wont take effect. Thanks for all the help.
<%= f.date_select :created_at,
:order => [:month, :day, :year],
:prompt => {month: 'Birth Month', day: 'Birth Day', year: 'Birth Year'},
:start_year => Time.now.year,
:end_year => 1920,
:class => 'SelectDropDown' %>
the form helper that I like is called simple_form. When I need to add a date picker I have been using bootstrap3-datetimepicker-rails
Setup:
File #app/assets/javascripts/application.js
$(document).ready(function() {
$('.datetimepicker').datetimepicker({});
return $('.datepicker').datetimepicker({
format: 'YYYY/MM/DD'
});
});
});
Now to apply it to a form
= f.input :date_select, as: :string, input_html: { class: 'datetimepicker', value: "#{f.created_at}" }
I hope that this helps
try to use html_options for class:
<%= f.date_select :created_at,
order: [:month, :day, :year],
prompt: {month: 'Birth Month', day: 'Birth Day', year: 'Birth Year'},
start_year: Time.now.year,
end_year: 1920,
html_options: {class: "SelectDropDown"} %>
for more details check data_select
my code looks like this
<div class="field form-group">
<%= f.label :date_of_birth %><br />
<%= date_select :date_of_birth, {order: [:month, :day, :year],
prompt: { day: 'Select day', month: 'Select month', year: 'Select year' },
start_year:1950, end_year: Date.today.year}, {required: true}, class: "form-control" %>
</div>
And result is in this photo
What i want that year selection be from 1950 to now.
Thanks for help!
The following code works perfectly for me:
<%= f.date_select( :date_of_birth, { :order => [:month, :day, :year], :start_year => 1950, :end_year => Date.today.year }, { :required => true, :class => "form-control" }) %>
Note that my date_select control is prepended with f, for the form it belongs to... I think that might be your problem.
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' }
I have 2 date fields, date started and date finished. I want to have a prompt for each, as in like on the page's first load, it will display the text "please select".
As you can see the code below, I have included prompt but it is not working.
<%= f.input :year_started, prompt: "Please select", as: :date, label: "Date started", start_year: Date.today.year, end_year: Date.today.year - 100, discard_day: true, order: [:month, :year], include_blank: true, default: nil, :input_html => { :class => 'profile-date' }, :required => false %>
<%= f.input :year_finished, prompt: "Please select", as: :date, label: "Date finished", start_year: Date.today.year + 7, end_year: Date.today.year - 100, discard_day: true, order: [:month, :year], include_blank: true, default: nil, :input_html => { :class => 'profile-date' }, hint: "Or expected graduation month and year.", :required => false %>
Can someone please help me how to get this done in date select. Thanks