Skip to content

Better groups and new validation mechanic #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
basic: path.resolve("dev", "projects", "basic", "main.js"),
mselect: path.resolve("dev", "projects", "multiselect", "main.js"),
grouping: path.resolve("dev", "projects", "grouping", "main.js"),
multi: path.resolve("dev", "projects", "multi", "main.js"),
checklist: path.resolve("dev", "projects", "checklist", "main.js"),
picker: path.resolve("dev", "projects", "picker", "main.js")
},
Expand Down
3 changes: 1 addition & 2 deletions dev/projects/basic/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export default {

formOptions: {
validateAfterLoad: true,
validateAfterChanged: true,
validateBeforeSave: true
validateAfterChanged: true
}
};
},
Expand Down
42 changes: 23 additions & 19 deletions dev/projects/full/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export default {

formOptions: {
validateAfterLoad: true,
validateAfterChanged: true,
validateBeforeSave: true
validateAfterChanged: true
}
};
},
Expand Down Expand Up @@ -118,7 +117,7 @@ export default {
},

onValidated(res, errors) {
console.log("VFG validated:", res, errors);
console.log("onValidated VFG validated:", arguments, res, errors);
},

generateModel() {
Expand All @@ -145,32 +144,36 @@ export default {
},

saveModel() {
console.log("Save model...");
if (this.formOptions.validateBeforeSave === false || this.validate()) {
this.mergeModelValues();

if (this.isNewModel) {
this.rows.push(this.model);
this.selectRow(null, this.model, false);
console.log("Save model...", this.validate, typeof this.validate);
this.validate().then(
(test) => {
console.log("saveModel", test);
this.mergeModelValues();

if (this.isNewModel) {
this.rows.push(this.model);
this.selectRow(null, this.model, false);
}
},
(error) => {
// Validation error
console.warn("Error saving model...", error);
}
} else {
console.warn("Error saving model...");
// Validation error
}
);
},

mergeModelValues() {
let model = this.model;
if (model && this.selected.length > 0) {
each(this.selected, row => {
each(this.selected, (row) => {
merge(row, model);
});
}
},

deleteModel() {
if (this.selected.length > 0) {
each(this.selected, row => {
each(this.selected, (row) => {
let index = this.rows.indexOf(row);
this.rows.splice(index, 1);
});
Expand All @@ -181,15 +184,16 @@ export default {
getNextID() {
let id = 0;

each(this.rows, row => {
each(this.rows, (row) => {
if (row.id > id) id = row.id;
});

return ++id;
},

validate() {
// console.log("validate", this.$refs.form, this.$refs.form.validate());
console.log("APP validate", this.$refs.form, typeof this.$refs.form.validate);

return this.$refs.form.validate();
},

Expand All @@ -199,7 +203,7 @@ export default {

getLocation(model) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(pos => {
navigator.geolocation.getCurrentPosition((pos) => {
if (!model.address) model.address = {};
if (!model.address.geo) model.address.geo = {};
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
Expand Down
48 changes: 24 additions & 24 deletions dev/projects/full/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,30 +461,30 @@ export default {
}
]
},
{
type: "staticMap",
model: "address.geo",
label: "Map",
visible: false,
fieldOptions: {
lat: "latitude",
lng: "longitude",
zoom: 6,
sizeX: 640,
sizeY: 640,
scale: 1,
format: "png",
// maptype:"satellite",
language: "FR-fr",
// region:
markers: "color:blue%7Clabel:S%7C43.107733,4.541936"
// path:
// visible:
// style:"feature:road.highway%7Celement:labels.text.stroke%7Cvisibility:on%7Ccolor:0xb06eba&style=feature:road.highway%7Celement:labels.text.fill%7Cvisibility:on%7Ccolor:0xffffff",
// key:
// signature:
}
},
// {
// type: "staticMap",
// model: "address.geo",
// label: "Map",
// visible: false,
// fieldOptions: {
// lat: "latitude",
// lng: "longitude",
// zoom: 6,
// sizeX: 640,
// sizeY: 640,
// scale: 1,
// format: "png",
// // maptype:"satellite",
// language: "FR-fr",
// // region:
// markers: "color:blue%7Clabel:S%7C43.107733,4.541936"
// // path:
// // visible:
// // style:"feature:road.highway%7Celement:labels.text.stroke%7Cvisibility:on%7Ccolor:0xb06eba&style=feature:road.highway%7Celement:labels.text.fill%7Cvisibility:on%7Ccolor:0xffffff",
// // key:
// // signature:
// }
// },
{
type: "switch",
model: "status",
Expand Down
63 changes: 50 additions & 13 deletions dev/projects/grouping/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,44 @@ export default {
more: "More",
things: "Things"
},
single: "blah"
single: "blah",
subname: ""
},

schema: {
groups: [
fields: [
{
type: "group",
legend: "Contact Details",
tag: "div",
fields: [
{
type: "input",
model: "name",
label: "Name",
fieldOptions: {
inputType: "text"
}
},
required: true,
validator: ["required"]
},
{
type: "group",
legend: "Subgroup",
styleClasses: "subgroup",
tag: "fieldset",
fields: [
{
type: "input",
model: "subname",
label: "Name",
fieldOptions: {
inputType: "text"
},
required: true,
validator: ["required"]
}
]
},
{
type: "input",
Expand All @@ -56,6 +79,17 @@ export default {
]
},
{
type: "input",
model: "single",
label: "Single field (without group)",
fieldOptions: {
inputType: "text"
},
required: true,
validator: ["string"]
},
{
type: "group",
legend: "Other Details",
fields: [
{
Expand All @@ -76,20 +110,12 @@ export default {
}
]
}
],
fields: [
{
type: "input",
model: "single",
label: "Single field (without group)",
fieldOptions: {
inputType: "text"
}
}
]
},

formOptions: {
validateAfterLoad: true,
validateAfterChanged: true,
fieldIdPrefix: "frm1-"
}
};
Expand All @@ -103,4 +129,15 @@ export default {

<style lang="scss">
@import "../../style.scss";
.field-group {
border: 2px solid #bbb;
padding: 8px;
border-radius: 4px;
}
.subgroup {
border-color: goldenrod;
legend {
color: #00268d;
}
}
</style>
Loading