mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #4045 from flashbackzoo/pulls/gridfield
Don't submit when disabled buttons are clicked
This commit is contained in:
commit
e81fdad14a
@ -137,6 +137,12 @@
|
||||
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){
|
||||
|
Loading…
x
Reference in New Issue
Block a user