diff --git a/javascript/GridField.js b/javascript/GridField.js index 20981a235..5472547a8 100644 --- a/javascript/GridField.js +++ b/javascript/GridField.js @@ -136,6 +136,12 @@ $('.ss-gridfield .action').entwine({ onclick: function(e){ var filterState='show'; //filterstate should equal current state. + + // If the button is disabled, do nothing. + if (this.button('option', 'disabled')) { + e.preventDefault(); + return; + } if(this.hasClass('ss-gridfield-button-close') || !(this.closest('.ss-gridfield').hasClass('show-filter'))){ filterState='hidden'; @@ -146,6 +152,34 @@ } }); + /** + * Don't allow users to submit empty values in grid field auto complete inputs. + */ + $('.ss-gridfield .add-existing-autocompleter').entwine({ + onbuttoncreate: function () { + var self = this; + + this.toggleDisabled(); + + this.find('input[type="text"]').on('keyup', function () { + self.toggleDisabled(); + }); + }, + onunmatch: function () { + this.find('input[type="text"]').off('keyup'); + }, + toggleDisabled: function () { + var $button = this.find('.ss-ui-button'), + $input = this.find('input[type="text"]'), + inputHasValue = $input.val() !== '', + buttonDisabled = $button.is(':disabled'); + + if ((inputHasValue && buttonDisabled) || (!inputHasValue && !buttonDisabled)) { + $button.button("option", "disabled", !buttonDisabled); + } + } + }); + // Covers both tabular delete button, and the button on the detail form $('.ss-gridfield .col-buttons .action.gridfield-button-delete, .cms-edit-form .Actions button.action.action-delete').entwine({ onclick: function(e){