Skip to content
Permalink
Browse files

Merge pull request #7229 from mvdbeek/backport_sliding_validator

[19.01] Backport #7183 input element listener
  • Loading branch information...
dannon committed Jan 17, 2019
2 parents 7c13cdf + 9765146 commit d460d218ad898242046c2422aa211fe6a4830462
Showing with 18 additions and 2 deletions.
  1. +11 −0 client/galaxy/scripts/mvc/form/form-input.js
  2. +7 −2 client/galaxy/scripts/mvc/ui/ui-slider.js
@@ -69,6 +69,17 @@ export default Backbone.View.extend({
self.reset();
});
}

// add error listener
if (this.field.model) {
this.listenTo(this.field.model, "error", message => {
if (message) {
this.error(message);
} else {
this.reset();
}
});
}
},

/** Set backdrop for input element */
@@ -103,9 +103,11 @@ var View = Backbone.View.extend({

/** Set and return the current value */
value: function(new_val) {
var options = this.model.attributes;
if (new_val !== undefined) {
if (new_val !== null && new_val !== "" && !this._isParameter(new_val)) {
let options = this.model.attributes;
let original_val = new_val;
let is_value = new_val !== null && new_val !== "" && !this._isParameter(new_val);
if (is_value) {
if (isNaN(new_val)) {
new_val = 0;
}
@@ -122,6 +124,9 @@ var View = Backbone.View.extend({
this.model.set("value", new_val);
this.model.trigger("change");
options.onchange(new_val);
let has_changed = is_value && parseInt(original_val) !== parseInt(new_val);
let message = has_changed ? "This value was invalid or out-of-range. It has been auto-corrected." : null;
this.model.trigger("error", message);
}
return this.model.get("value");
},

0 comments on commit d460d21

Please sign in to comment.
You can’t perform that action at this time.