Skip to content

Commit

Permalink
Remove deferred.pipe
Browse files Browse the repository at this point in the history
Remove the debugging-statement and revert dist/doc

Remove deferred.pipe

Remove the debugging-statement and revert dist/doc

undo formatting
  • Loading branch information
Abraham Przewodnik committed Dec 10, 2020
1 parent 0a8ac0a commit ad76cf6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
22 changes: 14 additions & 8 deletions src/parsley/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ var Base = function () {
Base.prototype = {
asyncSupport: true, // Deprecated

_pipeAccordingToValidationResult: function () {
var pipe = () => {
var r = $.Deferred();
if (true !== this.validationResult)
r.reject();
return r.resolve().promise();
};
return [pipe, pipe];
_pipeAccordingToValidationResult: function (deferred) {
return $.Deferred((newDefer) => {
const handle = () => {
var r = true === this.validationResult ?
$.Deferred().resolve():
$.Deferred().reject();
r.promise()
.progress(newDefer.notify)
.done(newDefer.resolve)
.fail(newDefer.reject)
}
deferred.done(handle)
deferred.fail(handle)
})
},

actualizeOptions: function () {
Expand Down
13 changes: 7 additions & 6 deletions src/parsley/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ Field.prototype = {
// Field Validate event. `this.value` could be altered for custom needs
this._trigger('validate');

return this.whenValid({force, value: this.value, _refreshed: true})
.always(() => { this._reflowUI(); })
.done(() => { this._trigger('success'); })
.fail(() => { this._trigger('error'); })
.always(() => { this._trigger('validated'); })
.pipe(...this._pipeAccordingToValidationResult());
return this._pipeAccordingToValidationResult(
this.whenValid({force, value: this.value, _refreshed: true})
.always(() => { this._reflowUI(); })
.done(() => { this._trigger('success'); })
.fail(() => { this._trigger('error'); })
.always(() => { this._trigger('validated'); })
);
},

hasConstraints: function () {
Expand Down
19 changes: 10 additions & 9 deletions src/parsley/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ Form.prototype = {
return $.map(this.fields, field => field.whenValidate({force, group}));
});

return Utils.all(promises)
.done( () => { this._trigger('success'); })
.fail( () => {
this.validationResult = false;
this.focus();
this._trigger('error');
})
.always(() => { this._trigger('validated'); })
.pipe(...this._pipeAccordingToValidationResult());
return this._pipeAccordingToValidationResult(
Utils.all(promises)
.done( () => { this._trigger('success'); })
.fail( () => {
this.validationResult = false;
this.focus();
this._trigger('error');
})
.always(() => { this._trigger('validated'); })
);
},

// Iterate over refreshed fields, and stop on first failure.
Expand Down

0 comments on commit ad76cf6

Please sign in to comment.