Do validation before enabling the Save button.

This commit is contained in:
Ashesh Vashi
2015-12-04 15:33:16 +05:30
parent 537df154fe
commit 57d6c3b406
3 changed files with 74 additions and 6 deletions

View File

@@ -128,6 +128,32 @@
'</div>'
].join("\n"));
Backform.Control.prototype.clearInvalid = function() {
this.$el.removeClass(Backform.errorClassName);
this.$el.find(".pgadmin-control-error-message").remove();
return this;
};
Backform.Control.prototype.updateInvalid = function() {
var self = this;
var errorModel = this.model.errorModel;
if (!(errorModel instanceof Backbone.Model)) return this;
this.clearInvalid();
this.$el.find(':input').not('button').each(function(ix, el) {
var attrArr = $(el).attr('name').split('.'),
name = attrArr.shift(),
path = attrArr.join('.'),
error = self.keyPathAccessor(errorModel.toJSON(), $(el).attr('name'));
if (_.isEmpty(error)) return;
self.$el.addClass(Backform.errorClassName).append(
$("<div></div>").addClass('pgadmin-control-error-message col-xs-12 help-block').text(error)
);
});
};
var ReadonlyOptionControl = Backform.ReadonlyOptionControl = Backform.SelectControl.extend({
template: _.template([
'<label class="<%=Backform.controlLabelClassName%>"><%=label%></label>',