Skip to content

Commit ed16bac

Browse files
author
Duncan Lock
committed
Merge branch 'master' into better-accessibility-labels
2 parents 8851d63 + 5105f39 commit ed16bac

File tree

10 files changed

+109
-22
lines changed

10 files changed

+109
-22
lines changed

dev/checklist/app.vue

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template lang="html">
2+
<div>
3+
<vue-form-generator :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
4+
<pre><code>{{ model }}</code></pre>
5+
</div>
6+
</template>
7+
8+
<script>
9+
import Vue from "vue";
10+
import { validators } from "../../src";
11+
12+
export default {
13+
data () {
14+
return {
15+
model: {
16+
skills: ["Javascript", "VueJS"]
17+
},
18+
19+
schema: {
20+
fields: [
21+
{
22+
type: "checklist",
23+
label: "Skills",
24+
model: "skills",
25+
required: true,
26+
min: 2,
27+
listBox: true,
28+
values: ["HTML5", "Javascript", "CSS3", "CoffeeScript", "AngularJS", "ReactJS", "VueJS"],
29+
validator: validators.array,
30+
onChanged(model) {
31+
console.log("skills changed to", model.skills);
32+
},
33+
onValidated(model, errors) {
34+
console.log("skills validated:", errors);
35+
}
36+
}
37+
]
38+
},
39+
40+
formOptions: {
41+
validateAfterChanged: true
42+
}
43+
}
44+
},
45+
46+
created() {
47+
window.app = this;
48+
}
49+
}
50+
</script>

dev/checklist/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>vue-form-generator multiselect demo</title>
6+
</head>
7+
<body>
8+
<div class="container-fluid"></div>
9+
<div id="app"></div>
10+
<script src="/checklist.js"></script>
11+
</body>
12+
</html>

dev/checklist/main.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Vue from "vue";
2+
import VueFormGenerator from "../../src";
3+
Vue.use(VueFormGenerator);
4+
5+
import App from './app.vue';
6+
7+
new Vue({
8+
...App
9+
}).$mount('#app');

dev/full/app.vue

+16
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@
195195
196196
modelUpdated(newVal, schema) {
197197
console.log("main model has updated", newVal, schema);
198+
},
199+
200+
201+
getLocation(model) {
202+
if (navigator.geolocation) {
203+
navigator.geolocation.getCurrentPosition((pos) => {
204+
if (!model.address)
205+
model.address = {};
206+
if (!model.address.geo)
207+
model.address.geo = {};
208+
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
209+
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
210+
});
211+
} else {
212+
alert("Geolocation is not supported by this browser.");
213+
}
198214
}
199215
200216

dev/full/schema.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,7 @@ module.exports = {
351351
classes: "btn-location",
352352
label: "Current location",
353353
onclick: function(model) {
354-
if (navigator.geolocation) {
355-
navigator.geolocation.getCurrentPosition((pos) => {
356-
if (!model.address)
357-
model.address = {};
358-
if (!model.address.geo)
359-
model.address.geo = {};
360-
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
361-
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
362-
});
363-
} else {
364-
alert("Geolocation is not supported by this browser.");
365-
}
354+
return this.$parent.getLocation(model);
366355
}
367356
}, {
368357
classes: "btn-clear",

dist/vfg-core.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vfg.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fields/core/fieldChecklist.vue

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</template>
2020

2121
<script>
22-
import {isObject, isNil} from "lodash";
22+
import {isObject, isNil, clone} from "lodash";
2323
import abstractField from "../abstractField";
2424
2525
export default {
@@ -90,9 +90,15 @@
9090
}
9191
9292
if (event.target.checked) {
93-
this.value.push(this.getItemValue(item));
93+
// Note: If you modify this.value array, it won't trigger the `set` in computed field
94+
const arr = clone(this.value);
95+
arr.push(this.getItemValue(item));
96+
this.value = arr;
9497
} else {
95-
this.value.splice(this.value.indexOf(this.getItemValue(item)), 1);
98+
// Note: If you modify this.value array, it won't trigger the `set` in computed field
99+
const arr = clone(this.value);
100+
arr.splice(this.value.indexOf(this.getItemValue(item)), 1);
101+
this.value = arr;
96102
}
97103
},
98104

src/formGenerator.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ div
1111
.field-wrap
1212
component(:is='getFieldType(field)', :disabled='fieldDisabled(field)', :model='model', :schema.sync='field', @model-updated='modelUpdated', @validated="onFieldValidated")
1313
.buttons(v-if='buttonVisibility(field)')
14-
button(v-for='btn in field.buttons', @click='btn.onclick(model, field)', :class='btn.classes') {{ btn.label }}
14+
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field)', :class='btn.classes') {{ btn.label }}
1515
.hint(v-if='field.hint') {{ field.hint }}
1616
.errors.help-block(v-if='fieldErrors(field).length > 0')
1717
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
@@ -250,6 +250,10 @@ div
250250
return field.featured;
251251
},
252252
253+
buttonClickHandler(btn, field) {
254+
return btn.onclick.call(this, this.model, field, this);
255+
},
256+
253257
// Child field executed validation
254258
onFieldValidated(res, errors, field) {
255259
// Remove old errors for this field

webpack.dev.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ module.exports = {
3333

3434
entry: {
3535
full: path.resolve("dev", "full", "main.js"),
36-
mselect: path.resolve("dev", "multiselect", "main.js")
36+
mselect: path.resolve("dev", "multiselect", "main.js"),
37+
checklist: path.resolve("dev", "checklist", "main.js")
3738
},
3839

3940
output: {

0 commit comments

Comments
 (0)