[Fix #376] Force every browser to use native input[type=date] on date champ
This commit is contained in:
parent
2653862fa7
commit
41a5ed59f3
4 changed files with 26 additions and 8 deletions
|
@ -2,10 +2,16 @@ class ChampDecorator < Draper::Decorator
|
|||
delegate_all
|
||||
|
||||
def value
|
||||
return object.value == 'on' ? 'Oui' : 'Non' if type_champ == 'checkbox'
|
||||
return JSON.parse(object.value).join(', ') if type_champ == 'multiple_drop_down_list' && object.value.present?
|
||||
if type_champ == "date" && object.value.present?
|
||||
Date.parse(object.value).strftime("%d/%m/%Y")
|
||||
elsif type_champ == 'checkbox'
|
||||
object.value == 'on' ? 'Oui' : 'Non'
|
||||
elsif type_champ == 'multiple_drop_down_list' && object.value.present?
|
||||
JSON.parse(object.value).join(', ')
|
||||
else
|
||||
object.value
|
||||
end
|
||||
end
|
||||
|
||||
def description_with_links
|
||||
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>').html_safe if description
|
||||
|
|
|
@ -12,12 +12,12 @@ class Champ < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def data_provide
|
||||
return 'datepicker' if (type_champ == 'datetime' || type_champ == 'date') && !(BROWSER.value.chrome? || BROWSER.value.edge?)
|
||||
return 'datepicker' if (type_champ == 'datetime') && !(BROWSER.value.chrome? || BROWSER.value.edge?)
|
||||
return 'typeahead' if type_champ == 'address'
|
||||
end
|
||||
|
||||
def data_date_format
|
||||
('dd/mm/yyyy' if type_champ == 'datetime' || type_champ == 'date')
|
||||
('dd/mm/yyyy' if type_champ == 'datetime')
|
||||
end
|
||||
|
||||
def same_hour? num
|
||||
|
|
|
@ -2,6 +2,4 @@
|
|||
placeholder: "JJ/MM/AAAA",
|
||||
id: "champs_#{champ.id}",
|
||||
value: champ.value,
|
||||
type: champ.type_champ,
|
||||
"data-provide": champ.data_provide,
|
||||
"data-date-format": champ.data_date_format }
|
||||
type: "date" }
|
||||
|
|
|
@ -34,5 +34,19 @@ describe ChampDecorator do
|
|||
it { is_expected.to eq '' }
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a date" do
|
||||
let(:type_champ) { :date }
|
||||
|
||||
context "when value is an ISO date" do
|
||||
before { champ.update value: "2017-12-31" }
|
||||
it { is_expected.to eq "31/12/2017" }
|
||||
end
|
||||
|
||||
context "when value is empty" do
|
||||
before { champ.update value: nil }
|
||||
it { is_expected.to eq nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue