Explication: add champ in edit formulaire

This commit is contained in:
Simon Lehericey 2017-03-14 13:58:21 +01:00
parent fcca0bb247
commit d250cafccc
3 changed files with 19 additions and 15 deletions

View file

@ -23,13 +23,13 @@ function destroy_action(){
}
function on_change_type_de_champ_select (){
$("select.form-control.type_champ").on('change', function(e){
parent = $(this).parent().parent();
parent.removeClass('header_section');
parent.children(".drop_down_list").removeClass('show_inline');
$('.mandatory', parent).show();
switch(this.value){
case 'header_section':
@ -38,7 +38,9 @@ function on_change_type_de_champ_select (){
case 'drop_down_list':
parent.children(".drop_down_list").addClass('show_inline');
break;
case 'explication':
$('.mandatory', parent).hide();
break;
}
})
});
}

View file

@ -30,7 +30,7 @@ class TypeDeChamp < ActiveRecord::Base
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
before_validation :change_header_section_mandatory
before_validation :check_mandatory
def self.type_de_champs_list_fr
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
@ -40,8 +40,8 @@ class TypeDeChamp < ActiveRecord::Base
!(type_champ == 'textarea' || type_champ == 'header_section')
end
def change_header_section_mandatory
self.mandatory = false if self.type_champ == 'header_section'
def check_mandatory
self.mandatory = false if %w(header_section explication).include?(self.type_champ)
true
end
end

View file

@ -1,27 +1,29 @@
= f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
.form-inline{class:"#{ff.object.object.type_champ == 'header_section' ? 'header_section' : ''}"}
.form-inline{ class: (ff.object.object.type_champ == 'header_section' ? 'header_section' : '') }
.form-group.libelle
%h4 Libellé
= ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
.form-group.type
%h4 Type
= ff.select :type_champ, TypeDeChamp.type_de_champs_list_fr, {}, {class: 'form-control type_champ'}
= ff.select :type_champ, TypeDeChamp.type_de_champs_list_fr, {}, { class: 'form-control type_champ' }
.form-group.description
%h4 Description
= ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 2
= ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 3
.form-group.drop_down_list{class:"#{ff.object.object.type_champ == 'drop_down_list' ? 'show_inline' : ''}",style:'margin-right: 5px'}
.form-group.drop_down_list{ class: (ff.object.object.type_champ == 'drop_down_list' ? 'show_inline' : ''), style: 'margin-right: 5px' }
%h4 Liste déroulante
= ff.fields_for :drop_down_list_attributes, ff.object.object.drop_down_list do |fff|
= fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne.\nEcrire --valeur-- pour un séparateur.", rows: 3, cols: 30
= fff.hidden_field :id
- unless ff.object.object.class == TypeDeChampPrivate
.form-group.mandatory
%h4 Obligatoire ?
.center
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'
- hide_mandatory = (ff.object.object.class == TypeDeChampPrivate || ff.object.object.type_champ == 'explication')
.form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : '' }
%h4 Obligatoire ?
.center
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'
.form-group
= ff.hidden_field :order_place, value: ff.index