Merge pull request #5477 from betagouv/datetime_starts_pastyear
Usager : réduit l'amplitude des champs "Date et heure" de `1950 → 2100` à `L’année précédente → L’année actuelle + 50 ans`
This commit is contained in:
commit
b9b0bc40b7
3 changed files with 12 additions and 4 deletions
|
@ -56,4 +56,12 @@ module ChampHelper
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def datetime_start_year(date)
|
||||
if date == nil || date.year == 0 || date.year >= Date.today.year - 1
|
||||
Date.today.year - 1
|
||||
else
|
||||
date.year
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
- parsed_value = champ.value.present? ? Time.zone.parse(champ.value) : nil
|
||||
|
||||
.datetime
|
||||
= form.datetime_select(:value, selected: parsed_value, start_year: 1950, end_year: 2100, minute_step: 5, include_blank: true)
|
||||
= form.datetime_select(:value, selected: parsed_value, start_year: datetime_start_year(parsed_value), end_year: Date.today.year + 50, minute_step: 5, include_blank: true)
|
||||
|
|
|
@ -14,7 +14,7 @@ feature 'The user' do
|
|||
fill_in('text', with: 'super texte')
|
||||
fill_in('textarea', with: 'super textarea')
|
||||
fill_in('date', with: '12-12-2012')
|
||||
select_date_and_time(Time.zone.parse('06/01/1985 7h05'), form_id_for_datetime('datetime'))
|
||||
select_date_and_time(Time.zone.parse('06/01/2030 7h05'), form_id_for_datetime('datetime'))
|
||||
fill_in('number', with: '42')
|
||||
check('checkbox')
|
||||
choose('Madame')
|
||||
|
@ -50,7 +50,7 @@ feature 'The user' do
|
|||
expect(champ_value_for('text')).to eq('super texte')
|
||||
expect(champ_value_for('textarea')).to eq('super textarea')
|
||||
expect(champ_value_for('date')).to eq('2012-12-12')
|
||||
expect(champ_value_for('datetime')).to eq('06/01/1985 07:05')
|
||||
expect(champ_value_for('datetime')).to eq('06/01/2030 07:05')
|
||||
expect(champ_value_for('number')).to eq('42')
|
||||
expect(champ_value_for('checkbox')).to eq('on')
|
||||
expect(champ_value_for('civilite')).to eq('Mme')
|
||||
|
@ -74,7 +74,7 @@ feature 'The user' do
|
|||
expect(page).to have_field('text', with: 'super texte')
|
||||
expect(page).to have_field('textarea', with: 'super textarea')
|
||||
expect(page).to have_field('date', with: '2012-12-12')
|
||||
check_date_and_time(Time.zone.parse('06/01/1985 7:05'), form_id_for_datetime('datetime'))
|
||||
check_date_and_time(Time.zone.parse('06/01/2030 7:05'), form_id_for_datetime('datetime'))
|
||||
expect(page).to have_field('number', with: '42')
|
||||
expect(page).to have_checked_field('checkbox')
|
||||
expect(page).to have_checked_field('Madame')
|
||||
|
|
Loading…
Reference in a new issue