1
0
mirror of synced 2024-11-25 23:06:02 +03:00

Merge branch 'master' of github.com:wearebraid/vue-formulate

This commit is contained in:
Justin Schroeder 2018-11-20 11:55:38 -05:00
commit 40001b6b6a
7 changed files with 1391 additions and 1360 deletions

View File

@ -11,7 +11,7 @@ mechanism for building and validating forms with a centralized data store.
### Show and tell
You'll find an easy to use example, in [the example directory](https://github.com/wearebraid/vue-formulate/tree/master/example)
You'll find an easy to use example, in [the example directory](https://github.com/wearebraid/vue-formulate/tree/master/example)
as well as a live demo available at: [demo.vueformulate.com](https://demo.vueformulate.com).
### Get Started
@ -159,8 +159,9 @@ Rule | Arguments
required | *none*
email | *none*
confirmed | confirmation field
number | *none*
You can add as many validation rules as you want to each `formulate-element`,
You can add as many validation rules as you want to each `formulate-element`,
simply chain your rules with pipes `|'. Additional arguments can be passed to
validation rules by using parenthesis after the rule name:
@ -194,7 +195,7 @@ attribute on the `formulate-element`.
/>
```
Validation rules should return an error message string if they failed, or
Validation rules should return an error message string if they failed, or
`false` if the input data is valid.
Adding your own validation rules is easy. Just pass an additional object

6
dist/index.js vendored

File diff suppressed because one or more lines are too long

2706
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -192,6 +192,10 @@ export default {
type: [String, Number, Boolean],
default: () => false
},
pattern: {
type: [String, Number, Boolean],
default: () => false
},
minlength: {
type: [String, Number, Boolean],
default: () => false
@ -333,7 +337,7 @@ export default {
return show
},
attributes () {
return ['min', 'max', 'minlength', 'maxlength', 'placeholder', 'id', 'multiple']
return ['min', 'max', 'minlength', 'maxlength', 'placeholder', 'id', 'multiple', 'pattern']
.filter(prop => this[prop] !== false)
.reduce((attributes, attr) => {
attributes[attr] = this[attr]

View File

@ -2,5 +2,6 @@ export default {
required: ({label, value}) => `${label} is required`,
email: ({label, value}) => `${label} is invalid.`,
confirmed: ({label, value}) => `${label} does not match the confirmation field.`,
number: ({label, value}) => `${label} is not a number`,
default: ({label, value}) => `This field is invalid.`
}

View File

@ -8,6 +8,15 @@ export default {
return (!value || (Array.isArray(value) && !value.length)) ? error(...arguments) : false
},
/**
* Validates the field contains only numbers
* @param {Object} field
* @param {string} label
*/
async number ({value, error}) {
return isNaN(value) ? error(...arguments) : false
},
/**
* Validate email addresses
* @param {Object} field

View File

@ -12,6 +12,22 @@ test('test required rule failure', async t => {
t.is('namexyz', v)
})
test('test number no failure on empty', async t => {
let v = await rules.number({field: 'name', value: '', error, label: 'xyz'})
t.is(false, v)
})
test('test number failure not number', async t => {
let v = await rules.number({field: 'name', value: 't', error, label: 'xyz'})
t.is('string', typeof v)
t.is('namexyz', v)
})
test('test number is typeof number', async t => {
let v = await rules.number({field: 'name', value: '3', error, label: 'xyz'})
t.is(false, v)
})
test('test required rule empty array failure', async t => {
let v = await rules.required({field: 'name', value: [], error, label: 'xyz'})
t.is('namexyz', v)