add other option to liste deroulante champ

This commit is contained in:
kara Diaby 2021-10-12 18:07:10 +02:00
parent 8bc925ae50
commit dc35d9521f
6 changed files with 51 additions and 1 deletions

View file

@ -57,6 +57,7 @@ module NewAdministrateur
],
methods: [
:drop_down_list_value,
:drop_down_other,
:drop_down_secondary_libelle,
:drop_down_secondary_description,
:piece_justificative_template_filename,
@ -75,6 +76,7 @@ module NewAdministrateur
:parent_id,
:private,
:drop_down_list_value,
:drop_down_other,
:drop_down_secondary_libelle,
:drop_down_secondary_description,
:piece_justificative_template,
@ -98,6 +100,7 @@ module NewAdministrateur
:description,
:mandatory,
:drop_down_list_value,
:drop_down_other,
:drop_down_secondary_libelle,
:drop_down_secondary_description,
:piece_justificative_template,

View file

@ -11,6 +11,7 @@ import MoveButton from './MoveButton';
import TypeDeChampCarteOption from './TypeDeChampCarteOption';
import TypeDeChampCarteOptions from './TypeDeChampCarteOptions';
import TypeDeChampDropDownOptions from './TypeDeChampDropDownOptions';
import TypeDeChampDropDownOther from './TypeDeChampDropDownOther';
import TypeDeChampPieceJustificative from './TypeDeChampPieceJustificative';
import TypeDeChampRepetitionOptions from './TypeDeChampRepetitionOptions';
import TypeDeChampTypesSelect from './TypeDeChampTypesSelect';
@ -24,6 +25,7 @@ const TypeDeChamp = sortableElement(
'linked_drop_down_list'
].includes(typeDeChamp.type_champ);
const isLinkedDropDown = typeDeChamp.type_champ === 'linked_drop_down_list';
const isSimpleDropDown = typeDeChamp.type_champ === 'drop_down_list';
const isFile = typeDeChamp.type_champ === 'piece_justificative';
const isCarte = typeDeChamp.type_champ === 'carte';
const isExplication = typeDeChamp.type_champ === 'explication';
@ -137,6 +139,10 @@ const TypeDeChamp = sortableElement(
libelleHandler={updateHandlers.drop_down_secondary_libelle}
descriptionHandler={updateHandlers.drop_down_secondary_description}
/>
<TypeDeChampDropDownOther
isVisible={isSimpleDropDown}
handler={updateHandlers.drop_down_other}
/>
<TypeDeChampPieceJustificative
isVisible={isFile}
directUploadUrl={state.directUploadUrl}
@ -241,6 +247,7 @@ const OPTIONS_FIELDS = {
export const FIELDS = [
'description',
'drop_down_list_value',
'drop_down_other',
'libelle',
'mandatory',
'parent_id',

View file

@ -0,0 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';
function TypeDeChampDropDownOther({ isVisible, handler }) {
if (isVisible) {
return (
<div className="cell">
<label htmlFor={handler.id}>
<input
type="checkbox"
id={handler.id}
name={handler.name}
checked={!!handler.value}
onChange={handler.onChange}
className="small-margin small"
/>
Proposer une option &apos;autre&apos; avec un texte libre
</label>
</div>
);
}
return null;
}
TypeDeChampDropDownOther.propTypes = {
isVisible: PropTypes.bool,
handler: PropTypes.object
};
export default TypeDeChampDropDownOther;

View file

@ -38,6 +38,7 @@ class Champ < ApplicationRecord
:mandatory?,
:description,
:drop_down_list_options,
:drop_down_other,
:drop_down_list_options?,
:drop_down_list_disabled_options,
:drop_down_list_enabled_non_empty_options,

View file

@ -41,4 +41,12 @@ class Champs::DropDownListChamp < Champ
def enabled_non_empty_options
drop_down_list_enabled_non_empty_options
end
def other_value_present?
self.value.present? && self.options.exclude?(self.value)
end
def drop_down_other?
drop_down_other
end
end

View file

@ -58,7 +58,7 @@ class TypeDeChamp < ApplicationRecord
belongs_to :parent, class_name: 'TypeDeChamp', optional: true
has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy
store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation, :skip_content_type_pj_validation, :drop_down_secondary_libelle, :drop_down_secondary_description
store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation, :skip_content_type_pj_validation, :drop_down_secondary_libelle, :drop_down_secondary_description, :drop_down_other
has_many :revision_types_de_champ, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ
has_many :revisions, through: :revision_types_de_champ
@ -331,6 +331,7 @@ class TypeDeChamp < ApplicationRecord
],
methods: [
:drop_down_list_value,
:drop_down_other,
:piece_justificative_template_filename,
:piece_justificative_template_url,
:editable_options,