Add type de champ checkbox (boolean)
This commit is contained in:
parent
20a41ef172
commit
850f4366c8
5 changed files with 37 additions and 17 deletions
12
app/decorators/champ_decorator.rb
Normal file
12
app/decorators/champ_decorator.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class ChampDecorator < Draper::Decorator
|
||||
|
||||
def value
|
||||
if type_champ == 'checkbox'
|
||||
return object.value == 'on' ? 'Oui' : 'Non'
|
||||
end
|
||||
end
|
||||
|
||||
def type_champ
|
||||
object.type_de_champ.type_champ
|
||||
end
|
||||
end
|
|
@ -2,7 +2,8 @@ class TypeDeChamp < ActiveRecord::Base
|
|||
enum type_champs: {text: 'text',
|
||||
textarea: 'textarea',
|
||||
datetime: 'datetime',
|
||||
number: 'number'
|
||||
number: 'number',
|
||||
checkbox: 'checkbox'
|
||||
}
|
||||
|
||||
belongs_to :procedure
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
%th{ style: 'width:25%' }
|
||||
=champ.libelle
|
||||
%td
|
||||
=champ.value
|
||||
=champ.decorate.value
|
||||
.col-lg-6.col-md-6
|
||||
=render partial: '/dossiers/pieces_justificatives'
|
||||
%br
|
||||
|
|
|
@ -20,22 +20,28 @@
|
|||
-@champs.each do |champ|
|
||||
.row
|
||||
%div{class: "type_champ-#{champ.type_champ}"}
|
||||
%h4
|
||||
= champ.libelle
|
||||
|
||||
-if champ.type_champ == 'textarea'
|
||||
%textarea.form-control{name:"champs['#{champ.id}']",
|
||||
placeholder: champ.libelle,
|
||||
id: "champs_#{champ.id}"}
|
||||
=champ.value
|
||||
-if champ.type_champ == 'checkbox'
|
||||
%h4{style:'margin-left:15px;'}
|
||||
= champ.libelle
|
||||
%input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''}
|
||||
%input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')}
|
||||
-else
|
||||
%input.form-control{name:"champs['#{champ.id}']",
|
||||
placeholder: champ.libelle,
|
||||
id: "champs_#{champ.id}",
|
||||
value: champ.value,
|
||||
type:"#{champ.type_champ}",
|
||||
'data-provide' => ('datepicker' if champ.type_champ == 'datetime'),
|
||||
'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')}
|
||||
%h4
|
||||
= champ.libelle
|
||||
|
||||
-if champ.type_champ == 'textarea'
|
||||
%textarea.form-control{name:"champs['#{champ.id}']",
|
||||
placeholder: champ.libelle,
|
||||
id: "champs_#{champ.id}"}
|
||||
=champ.value
|
||||
-else
|
||||
%input.form-control{name:"champs['#{champ.id}']",
|
||||
placeholder: champ.libelle,
|
||||
id: "champs_#{champ.id}",
|
||||
value: champ.value,
|
||||
type:"#{champ.type_champ}",
|
||||
'data-provide' => ('datepicker' if champ.type_champ == 'datetime'),
|
||||
'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')}
|
||||
|
||||
-if !@procedure.lien_demarche.blank? || @procedure.cerfa_flag || @dossier.pieces_justificatives.size > 1
|
||||
%br
|
||||
|
|
|
@ -28,6 +28,7 @@ describe TypeDeChamp do
|
|||
it { is_expected.to allow_value('textarea').for(:type_champ) }
|
||||
it { is_expected.to allow_value('datetime').for(:type_champ) }
|
||||
it { is_expected.to allow_value('number').for(:type_champ) }
|
||||
it { is_expected.to allow_value('checkbox').for(:type_champ) }
|
||||
end
|
||||
|
||||
context 'order_place' do
|
||||
|
|
Loading…
Add table
Reference in a new issue