Skip to content

Commit

Permalink
fix checklist validation bug #194
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed May 18, 2017
1 parent 547ea2e commit bea085f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
50 changes: 50 additions & 0 deletions dev/checklist/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template lang="html">
<div>
<vue-form-generator :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
<pre><code>{{ model }}</code></pre>
</div>
</template>

<script>
import Vue from "vue";
import { validators } from "../../src";
export default {
data () {
return {
model: {
skills: ["Javascript", "VueJS"]
},
schema: {
fields: [
{
type: "checklist",
label: "Skills",
model: "skills",
required: true,
min: 2,
listBox: true,
values: ["HTML5", "Javascript", "CSS3", "CoffeeScript", "AngularJS", "ReactJS", "VueJS"],
validator: validators.array,
onChanged(model) {
console.log("skills changed to", model.skills);
},
onValidated(model, errors) {
console.log("skills validated:", errors);
}
}
]
},
formOptions: {
validateAfterChanged: true
}
}
},
created() {
window.app = this;
}
}
</script>
12 changes: 12 additions & 0 deletions dev/checklist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>vue-form-generator multiselect demo</title>
</head>
<body>
<div class="container-fluid"></div>
<div id="app"></div>
<script src="/checklist.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions dev/checklist/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Vue from "vue";
import VueFormGenerator from "../../src";
Vue.use(VueFormGenerator);

import App from './app.vue';

new Vue({
...App
}).$mount('#app');
12 changes: 9 additions & 3 deletions src/fields/core/fieldChecklist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</template>

<script>
import {isObject, isNil} from "lodash";
import {isObject, isNil, clone} from "lodash";
import abstractField from "../abstractField";
export default {
Expand Down Expand Up @@ -90,9 +90,15 @@
}
if (event.target.checked) {
this.value.push(this.getItemValue(item));
// Note: If you modify this.value array, it won't trigger the `set` in computed field
const arr = clone(this.value);
arr.push(this.getItemValue(item));
this.value = arr;
} else {
this.value.splice(this.value.indexOf(this.getItemValue(item)), 1);
// Note: If you modify this.value array, it won't trigger the `set` in computed field
const arr = clone(this.value);
arr.splice(this.value.indexOf(this.getItemValue(item)), 1);
this.value = arr;
}
},
Expand Down
3 changes: 2 additions & 1 deletion webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module.exports = {

entry: {
full: path.resolve("dev", "full", "main.js"),
mselect: path.resolve("dev", "multiselect", "main.js")
mselect: path.resolve("dev", "multiselect", "main.js"),
checklist: path.resolve("dev", "checklist", "main.js")
},

output: {
Expand Down

0 comments on commit bea085f

Please sign in to comment.