Skip to content
Snippets Groups Projects
Commit c9b6bcc3 authored by Sébastien DA ROCHA's avatar Sébastien DA ROCHA :bicyclist:
Browse files

Merge branch 'evol/redmine-ticket-11442-validation-customform' into 'develop'

validate customForm and increment position

See merge request !12
parents e31e0694 079b4139
No related branches found
No related tags found
1 merge request!12validate customForm and increment position
...@@ -24,7 +24,11 @@ ...@@ -24,7 +24,11 @@
@blur="updateStore" @blur="updateStore"
/> />
<small>{{ form.label.help_text }}</small> <small>{{ form.label.help_text }}</small>
{{ form.label.errors }} <ul id="errorlist" class="errorlist">
<li v-for="error in form.label.errors" :key="error">
{{ error }}
</li>
</ul>
</div> </div>
<div class="required field"> <div class="required field">
...@@ -39,9 +43,14 @@ ...@@ -39,9 +43,14 @@
@blur="updateStore" @blur="updateStore"
/> />
<small>{{ form.name.help_text }}</small> <small>{{ form.name.help_text }}</small>
{{ form.name.errors }} <ul id="errorlist" class="errorlist">
<li v-for="error in form.name.errors" :key="error">
{{ error }}
</li>
</ul>
</div> </div>
</div> </div>
<div class="three fields"> <div class="three fields">
<div class="required field"> <div class="required field">
<label :for="form.position.id_for_label">{{ <label :for="form.position.id_for_label">{{
...@@ -58,8 +67,13 @@ ...@@ -58,8 +67,13 @@
/> />
</div> </div>
<small>{{ form.position.help_text }}</small> <small>{{ form.position.help_text }}</small>
{{ form.position.errors }} <ul id="errorlist" class="errorlist">
<li v-for="error in form.position.errors" :key="error">
{{ error }}
</li>
</ul>
</div> </div>
<div class="required field"> <div class="required field">
<label :for="form.field_type.id_for_label">{{ <label :for="form.field_type.id_for_label">{{
form.field_type.label form.field_type.label
...@@ -70,7 +84,13 @@ ...@@ -70,7 +84,13 @@
:selected="selectedFieldType" :selected="selectedFieldType"
:selection.sync="selectedFieldType" :selection.sync="selectedFieldType"
/> />
<ul id="errorlist" class="errorlist">
<li v-for="error in form.field_type.errors" :key="error">
{{ error }}
</li>
</ul>
</div> </div>
<div <div
v-if="selectedFieldType === 'Liste de valeurs'" v-if="selectedFieldType === 'Liste de valeurs'"
class="field field-list-options required field" class="field field-list-options required field"
...@@ -87,7 +107,11 @@ ...@@ -87,7 +107,11 @@
class="options-field" class="options-field"
/> />
<small>{{ form.help_text }}</small> <small>{{ form.help_text }}</small>
{{ form.options.errors }} <ul id="errorlist" class="errorlist">
<li v-for="error in form.options.errors" :key="error">
{{ error }}
</li>
</ul>
</div> </div>
</div> </div>
</div> </div>
...@@ -120,7 +144,7 @@ export default { ...@@ -120,7 +144,7 @@ export default {
form: { form: {
dataKey: 0, dataKey: 0,
label: { label: {
errors: null, errors: [],
id_for_label: "label", id_for_label: "label",
label: "Label", label: "Label",
help_text: "Nom en language naturel du champ", help_text: "Nom en language naturel du champ",
...@@ -131,7 +155,7 @@ export default { ...@@ -131,7 +155,7 @@ export default {
value: null, value: null,
}, },
name: { name: {
errors: null, errors: [],
id_for_label: "name", id_for_label: "name",
label: "Nom", label: "Nom",
html_name: "name", html_name: "name",
...@@ -143,7 +167,7 @@ export default { ...@@ -143,7 +167,7 @@ export default {
value: null, value: null,
}, },
position: { position: {
errors: null, errors: [],
id_for_label: "position", id_for_label: "position",
label: "Position", label: "Position",
min_value: 0, // ! check if good values (not found) min_value: 0, // ! check if good values (not found)
...@@ -153,10 +177,10 @@ export default { ...@@ -153,10 +177,10 @@ export default {
field: { field: {
max_length: 128, // ! check if good values (not found) max_length: 128, // ! check if good values (not found)
}, },
value: 0, value: this.customForm.dataKey - 1,
}, },
field_type: { field_type: {
errors: null, errors: [],
id_for_label: "field_type", id_for_label: "field_type",
label: "Type de champ", label: "Type de champ",
html_name: "field_type", html_name: "field_type",
...@@ -164,10 +188,10 @@ export default { ...@@ -164,10 +188,10 @@ export default {
field: { field: {
max_length: 50, max_length: 50,
}, },
value: null, //* field to send to the backend value: "boolean",
}, },
options: { options: {
errors: null, errors: [],
id_for_label: "options", id_for_label: "options",
label: "Options", label: "Options",
html_name: "options", html_name: "options",
...@@ -246,6 +270,21 @@ export default { ...@@ -246,6 +270,21 @@ export default {
// TODO : supprimer les espaces pour chaque option au début et à la fin QUE à la validation // TODO : supprimer les espaces pour chaque option au début et à la fin QUE à la validation
return string.replace(/\s*,\s*/gi, ","); return string.replace(/\s*,\s*/gi, ",");
}, },
checkCustomForm() {
console.log("checkCustomForm");
console.log(this.form);
if (this.form.label.value === null) {
this.form.label.errors = ["Veuillez compléter ce champ."];
return false;
} else if (this.form.name.value === null) {
this.form.name.errors = ["Veuillez compléter ce champ."];
this.form.label.errors = [];
return false;
}
this.form.label.errors = [];
this.form.name.errors = [];
return true;
},
}, },
beforeDestroy() { beforeDestroy() {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<p v-if="action === 'create'"> <p v-if="action === 'create'">
Ces champs par défaut existent pour tous les types de signalement: Ces champs par défaut existent pour tous les types de signalement:
</p> </p>
<div class="two fields"> <div class="two fields">
<div class="required field"> <div class="required field">
<label :for="form.title.id_for_label">{{ form.title.label }}</label> <label :for="form.title.id_for_label">{{ form.title.label }}</label>
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
</li> </li>
</ul> </ul>
</div> </div>
<div class="required field"> <div class="required field">
<label :for="form.geom_type.id_for_label">{{ <label :for="form.geom_type.id_for_label">{{
form.geom_type.label form.geom_type.label
...@@ -109,6 +111,7 @@ ...@@ -109,6 +111,7 @@
:key="form.dataKey" :key="form.dataKey"
:dataKey="form.dataKey" :dataKey="form.dataKey"
:customForm="form" :customForm="form"
ref="customForms"
/> />
</div> </div>
...@@ -211,7 +214,7 @@ export default { ...@@ -211,7 +214,7 @@ export default {
max_length: 128, // ! Vérifier la valeur dans django max_length: 128, // ! Vérifier la valeur dans django
}, },
html_name: "geom_type", html_name: "geom_type",
value: "Point", value: "point",
}, },
}, },
reservedKeywords: [ reservedKeywords: [
...@@ -324,10 +327,19 @@ export default { ...@@ -324,10 +327,19 @@ export default {
}); });
}, },
checkForm() { checkCustomForms() {
for (const customForm of this.$refs.customForms) {
if (customForm.checkCustomForm() === false) {
return false;
}
}
return true; //* fallback if all customForms returned true
},
checkForms() {
if (this.form.title.value) { if (this.form.title.value) {
this.form.title.errors = []; this.form.title.errors = [];
return true; return this.checkCustomForms(); //* if customForms are ok, validate, if get out function
} else if ( } else if (
!this.form.title.errors.includes("Veuillez compléter ce champ.") // TODO : Gérer les autres champs !this.form.title.errors.includes("Veuillez compléter ce champ.") // TODO : Gérer les autres champs
) { ) {
...@@ -352,7 +364,7 @@ export default { ...@@ -352,7 +364,7 @@ export default {
sendFeatureType() { sendFeatureType() {
// * si édition d'une feature_type déja existante, faire un put // * si édition d'une feature_type déja existante, faire un put
const requestType = this.action === "edit" ? "put" : "post"; const requestType = this.action === "edit" ? "put" : "post";
if (this.checkForm()) { if (this.checkForms()) {
this.$store this.$store
.dispatch("feature_type/SEND_FEATURE_TYPE", requestType) .dispatch("feature_type/SEND_FEATURE_TYPE", requestType)
.then(({ status }) => { .then(({ status }) => {
...@@ -389,7 +401,7 @@ export default { ...@@ -389,7 +401,7 @@ export default {
async postFeatureTypeThenFeatures() { async postFeatureTypeThenFeatures() {
const requestType = this.action === "edit" ? "put" : "post"; const requestType = this.action === "edit" ? "put" : "post";
if (this.checkForm()) { if (this.checkForms()) {
await this.$store await this.$store
.dispatch("feature_type/SEND_FEATURE_TYPE", requestType) .dispatch("feature_type/SEND_FEATURE_TYPE", requestType)
.then(({ feature_type_slug }) => { .then(({ feature_type_slug }) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment