Skip to content

Commit

Permalink
fix listen set to true after update closes #681
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Jul 31, 2017
1 parent 5b4a4ba commit 691edeb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 24 additions & 9 deletions dist/vee-validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,17 @@ ErrorBag.prototype.count = function count () {
return this.items.length;
};

/**
* Finds and fetches the first error message for the specified field id.
*
* @param {String} id
*/
ErrorBag.prototype.firstById = function firstById (id) {
var error = find(this.items, function (i) { return i.id === id; });

return error ? error.msg : null;
};

/**
* Gets the first error message for a specific field.
*
Expand Down Expand Up @@ -1788,7 +1799,6 @@ Generator.generate = function generate (el, binding, vnode, options) {
if ( options === void 0 ) options = {};

var model = Generator.resolveModel(binding, vnode);

return {
name: Generator.resolveName(el, vnode),
el: el,
Expand Down Expand Up @@ -2085,7 +2095,7 @@ Field.prototype.update = function update (options) {
this.name = options.name || this.name || null;
this.rules = options.rules ? normalizeRules(options.rules) : this.rules;
this.model = options.model || this.model;
this.listen = options.listen !== false;
this.listen = options.listen !== undefined ? options.listen : this.listen;
this.classes = options.classes || this.classes || false;
this.classNames = options.classNames || this.classNames || DEFAULT_OPTIONS.classNames;
this.expression = JSON.stringify(options.expression);
Expand All @@ -2110,10 +2120,7 @@ Field.prototype.update = function update (options) {
return;
}

if (this.classes) {
this.updateClasses();
}

this.updateClasses();
this.addValueListeners();
this.updateAriaAttrs();
};
Expand Down Expand Up @@ -2379,6 +2386,15 @@ Field.prototype.updateAriaAttrs = function updateAriaAttrs () {
this.el.setAttribute('aria-invalid', this.flags.invalid ? 'true' : 'false');
};

/**
* Updates the custom validity for the field.
*/
Field.prototype.updateCustomValidity = function updateCustomValidity () {
if (this.isHeadless || !isCallable(this.el.setCustomValidity)) { return; }

this.el.setCustomValidity(this.flags.valid ? '' : (this.validator.errors.firstById(this.id) || ''));
};

/**
* Removes all listeners.
*/
Expand Down Expand Up @@ -3242,9 +3258,8 @@ Validator.prototype.validate = function validate (name, value, scope) {
field.flags.invalid = !result;
field.flags.validated = true;
field.updateAriaAttrs();
if (field.classes) {
field.updateClasses();
}
field.updateCustomValidity();
field.updateClasses();

return result;
});
Expand Down
2 changes: 1 addition & 1 deletion src/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default class Field {
this.name = options.name || this.name || null;
this.rules = options.rules ? normalizeRules(options.rules) : this.rules;
this.model = options.model || this.model;
this.listen = options.listen !== false;
this.listen = options.listen !== undefined ? options.listen : this.listen;
this.classes = options.classes || this.classes || false;
this.classNames = options.classNames || this.classNames || DEFAULT_OPTIONS.classNames;
this.expression = JSON.stringify(options.expression);
Expand Down

0 comments on commit 691edeb

Please sign in to comment.