Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 55bde39

Browse files
author
Lionel Bijaoui
committed
Rework on validation and events to allow for a more flexible structure
Use an event bus for most events Breaking: validate is a promise since now all validation is asynchronous
1 parent c505ec7 commit 55bde39

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

‎projects/basic/app.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ export default {
9797
9898
formOptions: {
9999
validateAfterLoad: true,
100-
validateAfterChanged: true,
101-
validateBeforeSave: true
100+
validateAfterChanged: true
102101
}
103102
};
104103
},

‎projects/full/app.vue

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ export default {
7575
7676
formOptions: {
7777
validateAfterLoad: true,
78-
validateAfterChanged: true,
79-
validateBeforeSave: true
78+
validateAfterChanged: true
8079
}
8180
};
8281
},
@@ -118,7 +117,7 @@ export default {
118117
},
119118
120119
onValidated(res, errors) {
121-
console.log("VFG validated:", res, errors);
120+
console.log("onValidated VFG validated:", arguments, res, errors);
122121
},
123122
124123
generateModel() {
@@ -145,32 +144,36 @@ export default {
145144
},
146145
147146
saveModel() {
148-
console.log("Save model...");
149-
if (this.formOptions.validateBeforeSave === false || this.validate()) {
150-
this.mergeModelValues();
151-
152-
if (this.isNewModel) {
153-
this.rows.push(this.model);
154-
this.selectRow(null, this.model, false);
147+
console.log("Save model...", this.validate, typeof this.validate);
148+
this.validate().then(
149+
(test) => {
150+
console.log("saveModel", test);
151+
this.mergeModelValues();
152+
153+
if (this.isNewModel) {
154+
this.rows.push(this.model);
155+
this.selectRow(null, this.model, false);
156+
}
157+
},
158+
(error) => {
159+
// Validation error
160+
console.warn("Error saving model...", error);
155161
}
156-
} else {
157-
console.warn("Error saving model...");
158-
// Validation error
159-
}
162+
);
160163
},
161164
162165
mergeModelValues() {
163166
let model = this.model;
164167
if (model && this.selected.length > 0) {
165-
each(this.selected, row => {
168+
each(this.selected, (row) => {
166169
merge(row, model);
167170
});
168171
}
169172
},
170173
171174
deleteModel() {
172175
if (this.selected.length > 0) {
173-
each(this.selected, row => {
176+
each(this.selected, (row) => {
174177
let index = this.rows.indexOf(row);
175178
this.rows.splice(index, 1);
176179
});
@@ -181,15 +184,16 @@ export default {
181184
getNextID() {
182185
let id = 0;
183186
184-
each(this.rows, row => {
187+
each(this.rows, (row) => {
185188
if (row.id > id) id = row.id;
186189
});
187190
188191
return ++id;
189192
},
190193
191194
validate() {
192-
// console.log("validate", this.$refs.form, this.$refs.form.validate());
195+
console.log("APP validate", this.$refs.form, typeof this.$refs.form.validate);
196+
193197
return this.$refs.form.validate();
194198
},
195199
@@ -199,7 +203,7 @@ export default {
199203
200204
getLocation(model) {
201205
if (navigator.geolocation) {
202-
navigator.geolocation.getCurrentPosition(pos => {
206+
navigator.geolocation.getCurrentPosition((pos) => {
203207
if (!model.address) model.address = {};
204208
if (!model.address.geo) model.address.geo = {};
205209
model.address.geo.latitude = pos.coords.latitude.toFixed(5);

‎projects/full/schema.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -461,30 +461,30 @@ export default {
461461
}
462462
]
463463
},
464-
{
465-
type: "staticMap",
466-
model: "address.geo",
467-
label: "Map",
468-
visible: false,
469-
fieldOptions: {
470-
lat: "latitude",
471-
lng: "longitude",
472-
zoom: 6,
473-
sizeX: 640,
474-
sizeY: 640,
475-
scale: 1,
476-
format: "png",
477-
// maptype:"satellite",
478-
language: "FR-fr",
479-
// region:
480-
markers: "color:blue%7Clabel:S%7C43.107733,4.541936"
481-
// path:
482-
// visible:
483-
// style:"feature:road.highway%7Celement:labels.text.stroke%7Cvisibility:on%7Ccolor:0xb06eba&style=feature:road.highway%7Celement:labels.text.fill%7Cvisibility:on%7Ccolor:0xffffff",
484-
// key:
485-
// signature:
486-
}
487-
},
464+
// {
465+
// type: "staticMap",
466+
// model: "address.geo",
467+
// label: "Map",
468+
// visible: false,
469+
// fieldOptions: {
470+
// lat: "latitude",
471+
// lng: "longitude",
472+
// zoom: 6,
473+
// sizeX: 640,
474+
// sizeY: 640,
475+
// scale: 1,
476+
// format: "png",
477+
// // maptype:"satellite",
478+
// language: "FR-fr",
479+
// // region:
480+
// markers: "color:blue%7Clabel:S%7C43.107733,4.541936"
481+
// // path:
482+
// // visible:
483+
// // style:"feature:road.highway%7Celement:labels.text.stroke%7Cvisibility:on%7Ccolor:0xb06eba&style=feature:road.highway%7Celement:labels.text.fill%7Cvisibility:on%7Ccolor:0xffffff",
484+
// // key:
485+
// // signature:
486+
// }
487+
// },
488488
{
489489
type: "switch",
490490
model: "status",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /