Skip to content

Commit

Permalink
add $attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
fergaldoyle committed Mar 23, 2018
1 parent 4f3f41a commit 878ae61
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions dist/vue-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ var validate = {
$pending: false,
$submitted: false,
$error: {},
$attrs: {},
_className: null,
_id: 'vf' + randomId(),
_setValidatorVadility: function _setValidatorVadility(validator, isValid) {
Expand Down Expand Up @@ -959,6 +960,10 @@ var validate = {
return;
}

if (attrValue) {
_this3.$attrs[validator] = attrValue;
}

var result = isFunction ? _this3._validators[validator](value, attrValue, vnode) : vm.custom[validator];

if (typeof result === 'boolean') {
Expand Down
2 changes: 1 addition & 1 deletion dist/vue-form.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions example/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<validate auto-label class="form-group">
<label>Sample component 1</label>
<custom-field-one required pattern="\d\d\d-\d\d\d" v-model="model.bbb" name="bbb" class="form-control"></custom-field-one>
<custom-field-one required pattern="\d\d\d-\d\d\d" v-model="model.aaa" name="aaa" class="form-control"></custom-field-one>
<small class="form-text text-muted">Component with validation attributes set on the component element</small>
<field-messages class="form-control-feedback">
<div>Success!</div>
Expand All @@ -28,19 +28,19 @@

<validate auto-label class="form-group">
<label>Sample component 2</label>
<custom-field-two required v-bind="sampleData" v-model="model.ccc" name="ccc" class="form-control"></custom-field-two>
<custom-field-two required v-bind="sampleData" v-model="model.bbb" name="bbb" class="form-control"></custom-field-two>
<small class="form-text text-muted">Component where validation attributes are props, along with v-bind</small>
<field-messages class="form-control-feedback">
<field-messages class="form-control-feedback" v-if="formstate.bbb">
<div>Success!</div>
<div slot="minlength">Field is too short</div>
<div slot="maxlength">Field is too long</div>
<div slot="minlength">Minimum allowed characters for this field is {{formstate.bbb.$attrs.minlength}}</div>
<div slot="maxlength">Maximum allowed characters for this field is {{formstate.bbb.$attrs.maxlength}}</div>
<div slot="required">Field is required</div>
</field-messages>
</validate>

<validate auto-label class="form-group">
<label>Sample component 2</label>
<dynamic-field name="aaa" :field="sampleDynamicField" v-model="model.aaa"></dynamic-field>
<label>Sample component 3</label>
<dynamic-field name="ccc" :field="sampleDynamicField" v-model="model.ccc"></dynamic-field>
<small class="form-text text-muted">Component where validation attributes are emitted within the component using the vf:validate event</small>
<field-messages class="form-control-feedback">
<div>Success!</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-form",
"version": "4.8.0",
"version": "4.8.1",
"description": "Form validation for Vue.js",
"main": "dist/vue-form.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/components/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default {
$pending: false,
$submitted: false,
$error: {},
$attrs: {},
_className: null,
_id: 'vf' + randomId(),
_setValidatorVadility(validator, isValid) {
Expand Down Expand Up @@ -212,6 +213,10 @@ export default {
return;
}

if(attrValue) {
this.$attrs[validator] = attrValue;
}

const result = isFunction ? this._validators[validator](value, attrValue, vnode) : vm.custom[validator];

if (typeof result === 'boolean') {
Expand Down

0 comments on commit 878ae61

Please sign in to comment.