diff --git a/docs/en_US/release_notes_4_28.rst b/docs/en_US/release_notes_4_28.rst index 5b15e12a5..d274117ad 100644 --- a/docs/en_US/release_notes_4_28.rst +++ b/docs/en_US/release_notes_4_28.rst @@ -22,6 +22,7 @@ Bug fixes ********* | `Issue #4639 `_ - Ensure that some fields should be disabled for the trigger in edit mode. +| `Issue #5736 `_ - Fixed an issue where the validation error message is shown twice. | `Issue #5842 `_ - Ensure that query history should be listed by date/time in descending order. | `Issue #5858 `_ - Ensure that search object functionality works with case insensitive string. | `Issue #5895 `_ - Fixed an issue where the suffix for Toast table size is not visible in the Statistics tab. diff --git a/web/pgadmin/browser/static/js/datamodel.js b/web/pgadmin/browser/static/js/datamodel.js index ce1a4706a..2275380c4 100644 --- a/web/pgadmin/browser/static/js/datamodel.js +++ b/web/pgadmin/browser/static/js/datamodel.js @@ -539,6 +539,8 @@ define([ // Let me listen to the my child invalid/valid messages self.on('pgadmin-session:model:invalid', self.onChildInvalid); + self.on('pgadmin-session:collection:changed', self.onChildCollectionChanged); + self.on('pgadmin-session:model-msg:changed', self.onModelChangedMsg); self.on('pgadmin-session:model:valid', self.onChildValid); self.on('pgadmin-session:changed', self.onChildChanged); self.on('pgadmin-session:added', self.onChildChanged); @@ -674,10 +676,14 @@ define([ !validate(self, (objName && [objName]))) { if (self.handler) { (self.handler).trigger('pgadmin-session:model:valid', self, self.handler); + (self.handler).trigger('pgadmin-session:collection:changed', self, self.handler); } else { self.trigger( 'pgadmin-session:valid', self.sessChanged(), self ); + self.trigger( + 'pgadmin-session:collection:changed', self.sessChanged(), self + ); } } else { msg = msg || _.values(self.errorModel.attributes)[0]; @@ -686,19 +692,84 @@ define([ (self.handler).trigger( 'pgadmin-session:model:invalid', msg, self, self.handler ); + (self.handler).trigger('pgadmin-session:collection:changed', self, self.handler); } else { self.trigger('pgadmin-session:invalid', msg, self); + self.trigger('pgadmin-session:collection:changed', self); } } } }, - onChildChanged: function() { + onChildCollectionChanged: function(obj, obj_hand) { + + var self = this; + + setTimeout(() => { + + var msg = null, + validate = function(m, attrs) { + if ('default_validate' in m && typeof(m.default_validate) == 'function') { + msg = m.default_validate(); + if (_.isString(msg)) { + return msg; + } + } + + if ('validate' in m && typeof(m.validate) == 'function') { + msg = m.validate(attrs); + + return msg; + } + return null; + }; + + let handler, parentTr; + + let collection = self.collection || obj_hand; + if(collection) { + var collection_selector = collection.attrName || collection.name; + let activeTab = $('.show.active div.'+collection_selector); + $(activeTab).find('.error-in-grid').removeClass('error-in-grid'); + + model_collection_exit : if (collection instanceof Backbone.Collection) { + + for (var cid in collection.models) { + let model = collection.models[cid]; + + for(let mod_obj of model.objects) { + let mod_attr = model.attributes[mod_obj]; + if (mod_attr && mod_attr.models.length > 0) { + for(let mod_attr_prop in mod_attr.models) { + if(validate(mod_attr.models[mod_attr_prop])) { + handler = mod_attr.models[mod_attr_prop]; + parentTr = model.parentTr; + break model_collection_exit; + } + } + } + } + } + } + } + + if(msg && handler) { + msg = msg || _.values(handler.errorModel.attributes)[0]; + + handler.trigger('pgadmin-session:model:invalid', msg, handler); + $(parentTr).addClass('error-in-grid'); + } + return this; + }, 120); + }, + + onChildChanged: function(obj) { var self = this; if (self.trackChanges && self.collection) { (self.collection).trigger('change', self); } + self.trigger('pgadmin-session:collection:changed', self, obj); }, stopSession: function() { @@ -710,6 +781,7 @@ define([ self.off('pgadmin-session:changed', self.onChildChanged); self.off('pgadmin-session:added', self.onChildChanged); self.off('pgadmin-session:removed', self.onChildChanged); + self.off('pgadmin-session:collection:changed', self.onChildCollectionChanged); } self.trackChanges = false; @@ -1090,6 +1162,7 @@ define([ // Let the parent/listener know about my status (valid/invalid). this.triggerValidationEvent.apply(this); + self.trigger('pgadmin-session:collection:changed', self); } return true; diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js index f48111b21..26f65cb72 100644 --- a/web/pgadmin/static/js/backform.pgadmin.js +++ b/web/pgadmin/static/js/backform.pgadmin.js @@ -1170,6 +1170,7 @@ define([ var uniqueCol = this.field.get('uniqueCol') || [], uniqueChangedAttr = [], self = this; + // Check if changed model attributes are also in unique columns. And then only check for uniqueness. if (newModel.attributes) { _.each(uniqueCol, function(col) { @@ -1386,6 +1387,10 @@ define([ }, }); + for(let i = 0; i < (collection.length); i++) { + collection.at(i).parentTr = self.grid.body.rows[i].$el; + } + // Render subNode grid var subNodeGrid = self.grid.render().$el; @@ -1461,6 +1466,9 @@ define([ var idx = collection.indexOf(m), newRow = self.grid.body.rows[idx].$el; + collection.get(m).parentTr = newRow; + m.parentTr = newRow; + newRow.addClass('new'); if(!$(newRow).pgMakeBackgridVisible('.backform-tab')){ // We can have subnode controls in Panels @@ -1480,25 +1488,11 @@ define([ }, updateInvalid: function() { var self = this, - errorModel = this.model.errorModel; + errorModel = self.model.errorModel; if (!(errorModel instanceof Backbone.Model)) return this; this.clearInvalid(); - - this.$el.find('.subnode-body').each(function() { - var error = self.keyPathAccessor( - errorModel.toJSON(), self.field.get('name') - ); - - if (_.isEmpty(error)) return; - - self.$el.addClass('subnode-error').append( - $('
').addClass( - 'pgadmin-control-error-message pg-el-offset-4 pg-el-8 help-block' - ).text(error) - ); - }); }, }); diff --git a/web/pgadmin/static/scss/_alert.scss b/web/pgadmin/static/scss/_alert.scss index 836f0af93..537675c7f 100644 --- a/web/pgadmin/static/scss/_alert.scss +++ b/web/pgadmin/static/scss/_alert.scss @@ -95,6 +95,12 @@ z-index: 1; } +.error-in-grid { + border-radius: $border-radius !important; + background: $alert-danger-bg !important; + color: $alert-danger-color !important; +} + .pg-prop-status-bar { padding: 5px;