Skip to content
Snippets Groups Projects
Commit 962dbdc4 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

fix default value on dropdown at feature creation

parent 2e13bab6
No related branches found
No related tags found
1 merge request!16validate forms for feature_edit (attachment & linkedFeatures)
...@@ -30,7 +30,11 @@ ...@@ -30,7 +30,11 @@
v-model="form.title.value" v-model="form.title.value"
@blur="updateStore" @blur="updateStore"
/> />
{{ form.title.errors }} <ul id="errorlist" class="errorlist">
<li v-for="error in form.title.errors" :key="error">
{{ error }}
</li>
</ul>
</div> </div>
<div class="required field"> <div class="required field">
<label :for="form.status.id_for_label">{{ <label :for="form.status.id_for_label">{{
...@@ -41,8 +45,11 @@ ...@@ -41,8 +45,11 @@
:selected="selected_status.name" :selected="selected_status.name"
:selection.sync="selected_status" :selection.sync="selected_status"
/> />
<ul id="errorlist" class="errorlist">
{{ form.status.errors }} <li v-for="error in form.status.errors" :key="error">
{{ error }}
</li>
</ul>
</div> </div>
</div> </div>
<div class="field"> <div class="field">
...@@ -289,7 +296,10 @@ export default { ...@@ -289,7 +296,10 @@ export default {
id_for_label: "status", id_for_label: "status",
html_name: "status", html_name: "status",
label: "Statut", label: "Statut",
value: "Brouillon", value: {
value: "draft",
name: "Brouillon",
},
}, },
description: { description: {
errors: null, errors: null,
...@@ -329,10 +339,12 @@ export default { ...@@ -329,10 +339,12 @@ export default {
selected_status: { selected_status: {
get() { get() {
console.log(this.form.status.value);
return this.form.status.value; return this.form.status.value;
}, },
set(newValue) { set(newValue) {
this.form.status.value = newValue; this.form.status.value = newValue;
console.log(this.form.status.value);
this.updateStore(); this.updateStore();
}, },
}, },
...@@ -355,15 +367,15 @@ export default { ...@@ -355,15 +367,15 @@ export default {
methods: { methods: {
initForm() { initForm() {
if (this.currentRouteName === "editer-signalement") { if (this.currentRouteName === "editer-signalement") {
for (let el in this.feature) { for (let key in this.feature) {
if (el && this.form[el]) { if (key && this.form[key]) {
if (el === "status") { if (key === "status") {
const value = this.feature[el]; const value = this.feature[key];
this.form[el].value = this.statusChoices.find( this.form[key].value = this.statusChoices.find(
(el) => el.value === value (key) => key.value === value
); );
} else { } else {
this.form[el].value = this.feature[el]; this.form[key].value = this.feature[key];
} }
} }
} }
...@@ -472,13 +484,29 @@ export default { ...@@ -472,13 +484,29 @@ export default {
}); });
}, },
postForm() { checkForms() {
if (this.form.title.value) { if (this.form.title.value) {
this.form.title.errors = null; this.form.title.errors = [];
this.$store.dispatch("feature/SEND_FEATURE", this.currentRouteName); return this.checkCustomForms(); //* if customForms are ok, validate, if get out function
} else { } else if (
this.form.title.errors = "Veuillez compléter ce champ."; !this.form.title.errors.includes("Veuillez compléter ce champ.") // TODO : Gérer les autres champs
) {
this.form.title.errors.push("Veuillez compléter ce champ.");
document
.getElementById("errorlist")
.scrollIntoView({ block: "end", inline: "nearest" });
} }
return false;
},
postForm() {
if (!this.checkForms()) return;
this.$store.dispatch("feature/SEND_FEATURE", this.currentRouteName);
// if (this.form.title.value) {
// this.form.title.errors = null;
// } else {
// this.form.title.errors = "Veuillez compléter ce champ.";
// }
}, },
onFeatureTypeLoaded() { onFeatureTypeLoaded() {
...@@ -766,7 +794,8 @@ export default { ...@@ -766,7 +794,8 @@ export default {
featureAPI featureAPI
.getFeatureAttachments(this.$route.params.slug_signal) .getFeatureAttachments(this.$route.params.slug_signal)
.then((data) => this.addExistingAttachementFormset(data)); .then((data) => this.addExistingAttachementFormset(data));
} else { //* be sure that previous attachemntFormset has been cleared for creation } else {
//* be sure that previous attachemntFormset has been cleared for creation
this.$store.commit("feature/CLEAR_ATTACHMENT_FORM"); this.$store.commit("feature/CLEAR_ATTACHMENT_FORM");
} }
}, },
......
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