mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Disable gridfield 'add' button when autocompleter is empty
This commit is contained in:
parent
d71e2ea552
commit
3a3c8c937b
@ -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