Newer
Older
Sébastien DA ROCHA
committed
<template>
<div v-if="field && field.field_type === 'char'">
v-if="displayLabels"
>
{{ field.label }}
</label>
Sébastien DA ROCHA
committed
<input
:id="field.name"
:value="field.value"
Sébastien DA ROCHA
committed
@blur="updateStore_extra_form"
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
Sébastien DA ROCHA
committed
</div>
<div v-else-if="field && field.field_type === 'list'">
v-if="displayLabels"
>
{{ field.label }}
</label>
Sébastien DA ROCHA
committed
<Dropdown
:options="field.options"
:selected="selected_extra_form_list"
:selection.sync="selected_extra_form_list"
Sébastien DA ROCHA
committed
/>
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
Sébastien DA ROCHA
committed
</div>
<div
v-else-if="field && field.field_type === 'pre_recorded_list'"
>
<label
v-if="displayLabels"
:for="field.name"
:class="{ required: field.is_mandatory }"
>
{{ field.label }}
</label>
<Multiselect
v-model="selectedPrerecordedValue"
:options="
selectedPrerecordedListValues[field.options[0]] ? selectedPrerecordedListValues[field.options[0]] : []
"
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
:options-limit="10"
:allow-empty="!field.is_mandatory"
track-by="label"
label="label"
:reset-after="false"
select-label=""
selected-label=""
deselect-label=""
:searchable="true"
:placeholder="'Recherchez une valeur de la liste pré-définie ...'"
:show-no-results="true"
:loading="loadingPrerecordedListValues"
:clear-on-select="false"
:preserve-search="false"
@search-change="search"
@select="selectPrerecordedValue"
>
<template slot="clear">
<div
v-if="selectedPrerecordedValue"
class="multiselect__clear"
@click.prevent.stop="clear"
>
<i
class="close icon"
aria-hidden="true"
/>
</div>
</template>
<span slot="noResult">
Aucun résultat.
</span>
<span slot="noOptions">
Saisissez les premiers caractères ...
</span>
</Multiselect>
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
</div>
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<div v-else-if="field && field.field_type === 'multi_choices_list'">
<label
v-if="displayLabels"
:for="field.name"
:class="{ required: field.is_mandatory }"
>
{{ field.label }}
</label>
<div
v-for="option in field.options"
:key="option"
class="ui checkbox"
>
<input
:id="option"
type="checkbox"
:checked="field.value && field.value.includes(option)"
:name="option"
@change="selectMultipleCheckbox"
>
<label :for="option">
{{ option }}
</label>
</div>
<!-- <Dropdown
:options="field.options"
:selected="selected_extra_form_list"
:selection.sync="selected_extra_form_list"
:required="field.is_mandatory"
/> -->
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
</div>
<div v-else-if="field && field.field_type === 'integer'">
v-if="displayLabels"
:for="field.name"
>
{{ field.label }}
</label>
Sébastien DA ROCHA
committed
<div class="ui input">
<!-- //* si click sur fléche dans champ input, pas de focus, donc pas de blur, donc utilisation de @change -->
<input
:id="field.name"
:value="field.value"
Sébastien DA ROCHA
committed
@change="updateStore_extra_form"
Sébastien DA ROCHA
committed
</div>
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
Sébastien DA ROCHA
committed
</div>
<div v-else-if="field && field.field_type === 'boolean'">
Sébastien DA ROCHA
committed
<div class="ui checkbox">
<input
Sébastien DA ROCHA
committed
type="checkbox"
:checked="field.value"
:name="field.name"
@change="updateStore_extra_form"
<label :for="field.name">
{{ displayLabels ? field.label : '' }}
Sébastien DA ROCHA
committed
</div>
</div>
<div v-else-if="field && field.field_type === 'date'">
v-if="displayLabels"
:for="field.name"
>
{{ field.label }}
</label>
Sébastien DA ROCHA
committed
<input
:id="field.name"
:value="field.value"
Sébastien DA ROCHA
committed
@blur="updateStore_extra_form"
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
Sébastien DA ROCHA
committed
</div>
<div v-else-if="field && field.field_type === 'decimal'">
v-if="displayLabels"
:for="field.name"
>
{{ field.label }}
</label>
Sébastien DA ROCHA
committed
<div class="ui input">
<input
:value="field.value"
Sébastien DA ROCHA
committed
type="number"
step=".01"
:name="field.name"
Sébastien DA ROCHA
committed
@change="updateStore_extra_form"
Sébastien DA ROCHA
committed
</div>
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
Sébastien DA ROCHA
committed
</div>
<div v-else-if="field && field.field_type === 'text'">
v-if="displayLabels"
:for="field.name"
>
{{ field.label }}
</label>
Sébastien DA ROCHA
committed
<textarea
:value="field.value"
Sébastien DA ROCHA
committed
:name="field.name"
Sébastien DA ROCHA
committed
rows="3"
@blur="updateStore_extra_form"
<ul
v-if="field.is_mandatory && error"
:id="`errorlist-extra-form-${field.name}`"
class="errorlist"
>
<li>
{{ error }}
</li>
</ul>
Sébastien DA ROCHA
committed
</div>
</template>
<script>
import Dropdown from '@/components/Dropdown.vue';
import Multiselect from 'vue-multiselect';
import { mapState, mapMutations, mapActions } from 'vuex';
Sébastien DA ROCHA
committed
export default {
Sébastien DA ROCHA
committed
components: {
Dropdown,
Sébastien DA ROCHA
committed
},
props: {
field: {
type: Object,
default: null,
}
},
Sébastien DA ROCHA
committed
error: null,
prerecordedListSearchQuery: null,
loadingPrerecordedListValues: false,
selectedPrerecordedValue: null,
selectedMultipleCheckbox: [],
Sébastien DA ROCHA
committed
computed: {
...mapState('feature-type', [
'selectedPrerecordedListValues'
]),
Sébastien DA ROCHA
committed
selected_extra_form_list: {
get() {
Sébastien DA ROCHA
committed
},
set(newValue) {
//* set the value selected in the dropdown
newExtraForm['value'] = newValue;
this.$store.commit('feature/UPDATE_EXTRA_FORM', newExtraForm);
Sébastien DA ROCHA
committed
},
},
displayLabels() {
return this.$route.name === 'editer-signalement' || this.$route.name === 'ajouter-signalement' || this.$route.name === 'editer-attribut-signalement';
Sébastien DA ROCHA
committed
},
watch: {
'field.value': function(newValue) {
if (newValue) {
this.error = null;
}
},
prerecordedListSearchQuery(newValue) {
this.loadingPrerecordedListValues = true;
this.GET_SELECTED_PRERECORDED_LIST_VALUES({
name: this.field.options[0],
pattern: newValue
})
.then(() => {
this.loadingPrerecordedListValues = false;
.catch(() => {
this.loadingPrerecordedListValues = false;
});
const { field_type, options, value } = this.field;
if (field_type === 'pre_recorded_list') {
this.loadingPrerecordedListValues = true;
this.GET_SELECTED_PRERECORDED_LIST_VALUES({
name: options[0],
pattern: ''
})
.then(() => {
this.loadingPrerecordedListValues = false;
})
.catch(() => {
this.loadingPrerecordedListValues = false;
});
if (value) {
this.selectedPrerecordedValue = { label: value };
}
} else if (field_type === 'multi_choices_list' && value) {
this.selectedMultipleCheckbox = value;
Sébastien DA ROCHA
committed
methods: {
...mapMutations('feature-type', [
'SET_SELECTED_PRERECORDED_LIST_VALUES'
]),
...mapActions('feature-type', [
'GET_SELECTED_PRERECORDED_LIST_VALUES'
]),
Sébastien DA ROCHA
committed
updateStore_extra_form(evt) {
if (this.field.field_type === 'boolean') {
newExtraForm['value'] = evt.target.checked; //* if checkbox use "checked"
} else if (this.field.field_type === 'multi_choices_list') {
newExtraForm['value'] = this.selectedMultipleCheckbox;
this.$store.commit('feature/UPDATE_EXTRA_FORM', newExtraForm);
Sébastien DA ROCHA
committed
},
checkForm() {
let isValid = true;
if (this.field.is_mandatory && !this.field.value) {
isValid = false;
this.error = 'Ce champ est obligatoire';
} else {
this.error = null;
}
return isValid;
},
search(text) {
this.prerecordedListSearchQuery = text;
},
selectPrerecordedValue(e) {
this.selectedPrerecordedValue = e.label;
this.prerecordedListSearchQuery = null;
this.updateStore_extra_form({ target: { value: this.selectedPrerecordedValue } });
},
clear() {
this.selectedPrerecordedValue = null;
this.prerecordedListSearchQuery = null;
},
selectMultipleCheckbox(e) {
const { checked, name } = e.target;
if (checked) {
this.selectedMultipleCheckbox.push(name);
} else {
this.selectedMultipleCheckbox = this.selectedMultipleCheckbox.filter((el) => el !== name);
}
this.updateStore_extra_form();
},
Sébastien DA ROCHA
committed
},
};
<style lang="less" scoped>
label.required:after {
content: ' *';
color: rgb(209, 0, 0);
}
.ui.checkbox {
margin-right: 2rem;
}