Skip to content

Commit

Permalink
implemented input-valid ad input events to enable notification of eve…
Browse files Browse the repository at this point in the history
…ry userinput, field match example, fixed console output handling, added ulfgebhardt to the authors, version bump to 0.5.17
  • Loading branch information
ulfgebhardt committed May 7, 2019
1 parent 0590729 commit d70d331
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@human-connection/styleguide",
"version": "0.5.16",
"version": "0.5.17",
"private": false,
"scripts": {
"serve": "http-server ./docs -o -s",
Expand Down Expand Up @@ -71,7 +71,8 @@
"authors": [
"appinteractive",
"roschaefer",
"visualjerk"
"visualjerk",
"ulfgebhardt"
],
"main": "./dist/system.umd.min.js",
"files": [
Expand Down
23 changes: 14 additions & 9 deletions src/system/components/data-input/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import Schema from 'async-validator'
import cloneDeep from 'clone-deep'
import dotProp from 'dot-prop'
// Disable warnings to console
Schema.warning = function() {}
/**
* Used for handling complex user input.
Expand Down Expand Up @@ -72,11 +74,6 @@ export default {
},
validate(cb) {
const validator = new Schema(this.schema)
// Prevent validator from printing to console
// eslint-disable-next-line
const warn = console.warn
// eslint-disable-next-line
console.warn = () => {}
validator.validate(this.newData, errors => {
if (errors) {
this.errors = errors.reduce((errorObj, error) => {
Expand All @@ -87,8 +84,6 @@ export default {
} else {
this.errors = null
}
// eslint-disable-next-line
console.warn = warn
this.notify(this.newData, this.errors)
if (!errors && cb && typeof cb === 'function') {
cb()
Expand All @@ -114,14 +109,24 @@ export default {
},
async update(model, value) {
dotProp.set(this.newData, model, value)
/**
* Fires after user input.
* Receives the current form data.
* The form data is not validated and can be invalid.
* This event is fired before the input-valid event.
*
* @event input
*/
await this.$emit('input', cloneDeep(this.newData))
this.validate(() => {
/**
* Fires after user input.
* Receives the current form data.
* This is only called if the form data is successfully validated.
*
* @event input
* @event input-valid
*/
this.$emit('input', cloneDeep(this.newData))
this.$emit('input-valid', cloneDeep(this.newData))
})
},
reset() {
Expand Down
30 changes: 28 additions & 2 deletions src/system/components/data-input/Form/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Use a schema to provide validation for the form inputs. Use scoped slots to get
v-model="formData"
@submit="handleSubmit"
@input="handleInput"
@input-valid="handleInputValid"
@reset="handleReset"
:schema="formSchema">
<template slot-scope="{ errors, reset }">
Expand All @@ -65,6 +66,12 @@ Use a schema to provide validation for the form inputs. Use scoped slots to get
label="Email"
type="email"
placeholder="Your email address ..."></ds-input>
<ds-input
icon="at"
model="emailConfirm"
label="Confirm Email"
type="email"
placeholder="Confirm your email address ..."></ds-input>
<ds-select
icon="user"
model="gender"
Expand All @@ -87,7 +94,7 @@ Use a schema to provide validation for the form inputs. Use scoped slots to get
Reset form
</ds-button>
<ds-button
:disabled="errors"
:disabled="disabled"
icon="save"
primary>
Save profile
Expand All @@ -113,13 +120,19 @@ Use a schema to provide validation for the form inputs. Use scoped slots to get
formSchema: {
name: { required: true, message: 'Fill in a name' },
email: { type: 'email', required: true, message: 'Fill in a valid email' },
emailConfirm: [
{ validator: this.matchEmail },
// the last entry is called first ¯\_(ツ)_/¯
{ type: 'email', required: true, message: 'Confirm your email'}
],
settings: {
type: 'object',
fields: {
status: { min: 20, max: 300, message: 'Write between 20 and 300 letters' }
}
}
}
},
disabled: true
}
},
methods: {
Expand All @@ -128,9 +141,22 @@ Use a schema to provide validation for the form inputs. Use scoped slots to get
},
handleInput(data) {
console.log('Input form ...', data)
this.disabled = true
},
handleInputValid(data) {
this.disabled = false
console.log('Input-valid form ...', data)
},
handleReset(data) {
console.log('Reset form ...', data)
},
matchEmail(rule, value, callback, source, options) {
var errors = [];
if(this.formData.email !== value) {
errors.push(new Error('EMail missmatch'));
}
callback(errors);
}
}
}
Expand Down

0 comments on commit d70d331

Please sign in to comment.