Skip to content

Instantly share code, notes, and snippets.

@wisetc
Last active December 27, 2017 14:00
Show Gist options
  • Select an option

  • Save wisetc/e44846c91c10a58a003ddfe8f1fde117 to your computer and use it in GitHub Desktop.

Select an option

Save wisetc/e44846c91c10a58a003ddfe8f1fde117 to your computer and use it in GitHub Desktop.
Promise.all
<script>
...
methods: {
...
validateRowForm(form, error, rules) {
return new Promise((resolve, reject) => {
new schema(rules).validate(form, (errors, fields) => {
if (fields) {
for (let k in fields) {
error[k] = {
isError: true,
message: fields[k][0].message
};
}
}
let valid = fields ? false : true;
resolve(valid);
});
});
},
validateAllRowForm() {
return new Promise((resolve, reject) => {
let promises = this.data.map(row => this.validateRowForm(row.__form__, row.__error__, this.rules))
Promise.all(promises).then(values => {
resolve(values.every(valid => valid))
})
})
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment