Fix datepicker workflow to match legacy behavior
- Implement proper button hiding/showing workflow for datepicker inputs - Buttons now hidden initially when datepicker opens - Buttons appear only after date selection, not immediately - Datepicker closes automatically after date selection - Enhanced CSS specificity for reliable button control - Robust fallback methods for datepicker closing - Update to version 25.0.5
This commit is contained in:
@@ -168,29 +168,40 @@
|
||||
|
||||
/* Bootstrap 5 inline editing fixes */
|
||||
.editable-inline .editableform {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: nowrap;
|
||||
display: inline-flex !important;
|
||||
flex-direction: row !important;
|
||||
align-items: center !important;
|
||||
gap: 0.5rem !important;
|
||||
flex-wrap: nowrap !important;
|
||||
}
|
||||
|
||||
.editable-inline .editable-input {
|
||||
flex-shrink: 1;
|
||||
min-width: 0;
|
||||
max-width: 200px; /* Prevent overly wide selects */
|
||||
flex-shrink: 1 !important;
|
||||
min-width: 0 !important;
|
||||
max-width: 200px !important; /* Prevent overly wide selects */
|
||||
display: inline-block !important;
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.editable-inline .editable-input select {
|
||||
max-width: 100%;
|
||||
min-width: 120px;
|
||||
max-width: 100% !important;
|
||||
min-width: 120px !important;
|
||||
}
|
||||
|
||||
.editable-inline .editable-buttons {
|
||||
flex-shrink: 0;
|
||||
margin-left: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
flex-shrink: 0 !important;
|
||||
margin-left: 0.5rem !important;
|
||||
margin-top: 0 !important;
|
||||
display: inline-flex !important;
|
||||
align-items: center !important;
|
||||
gap: 0.25rem !important;
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.editable-inline .control-group {
|
||||
white-space: nowrap !important;
|
||||
display: inline-flex !important;
|
||||
align-items: center !important;
|
||||
}
|
||||
|
||||
/* Improve button styling for Bootstrap 5 */
|
||||
@@ -204,3 +215,23 @@
|
||||
padding: 0.125rem 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* Hide buttons initially for datepicker inputs - using discovered DOM structure */
|
||||
/* Buttons are siblings to editable-input that contains datepicker */
|
||||
.editable-input:has(.input-group.date) + .editable-buttons,
|
||||
.editable-input:has(.input-group.datepicker-above) + .editable-buttons,
|
||||
/* Buttons might be in same container as editable-input */
|
||||
*:has(.editable-input .input-group.date) .editable-buttons,
|
||||
*:has(.editable-input .input-group.datepicker-above) .editable-buttons {
|
||||
display: none !important;
|
||||
visibility: hidden !important;
|
||||
}
|
||||
|
||||
/* Show buttons when they have the show-buttons class */
|
||||
.editable-input:has(.input-group.date) + .editable-buttons.show-buttons,
|
||||
.editable-input:has(.input-group.datepicker-above) + .editable-buttons.show-buttons,
|
||||
*:has(.editable-input .input-group.date) .editable-buttons.show-buttons,
|
||||
*:has(.editable-input .input-group.datepicker-above) .editable-buttons.show-buttons {
|
||||
display: inline-flex !important;
|
||||
visibility: visible !important;
|
||||
}
|
||||
|
@@ -33,11 +33,13 @@ $(function(){
|
||||
}
|
||||
|
||||
var Date = function (options) {
|
||||
console.log('Date input constructor called');
|
||||
this.init('date', options, Date.defaults);
|
||||
this.initPicker(options, Date.defaults);
|
||||
|
||||
// Ensure type is set correctly
|
||||
this.type = 'date';
|
||||
console.log('Date input initialized');
|
||||
};
|
||||
|
||||
$.fn.editableutils.inherit(Date, $.fn.editabletypes.abstractinput);
|
||||
@@ -77,23 +79,48 @@ $(function(){
|
||||
},
|
||||
|
||||
render: function () {
|
||||
console.log('Date render method called');
|
||||
// Ensure we have an input element
|
||||
if (!this.$input || !this.$input.length) {
|
||||
console.log('Date render: No input element found');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Date render: Input element found');
|
||||
|
||||
// Initialize datepicker immediately
|
||||
try {
|
||||
this.$input.datepicker(this.options.datepicker);
|
||||
console.log('Date render: Datepicker initialized');
|
||||
|
||||
// Force set the initial value if we have one
|
||||
if (this.value) {
|
||||
this.$input.datepicker('setDate', this.value);
|
||||
}
|
||||
} catch (error) {
|
||||
// Silently handle datepicker initialization errors
|
||||
console.log('Date render: Datepicker error:', error);
|
||||
}
|
||||
|
||||
// Use a more aggressive approach - hide buttons with multiple methods
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
// Try multiple selectors to find buttons
|
||||
var $buttons = self.$form ? self.$form.find('.editable-buttons') : $();
|
||||
if ($buttons.length === 0) {
|
||||
$buttons = self.$tpl.closest('.editableform').find('.editable-buttons');
|
||||
}
|
||||
if ($buttons.length === 0) {
|
||||
$buttons = self.$tpl.closest('.editable-container').find('.editable-buttons');
|
||||
}
|
||||
|
||||
console.log('Date render: Found buttons:', $buttons.length);
|
||||
if ($buttons.length > 0) {
|
||||
$buttons.hide();
|
||||
$buttons.css('display', 'none');
|
||||
console.log('Date render: Hidden buttons');
|
||||
}
|
||||
}, 100);
|
||||
|
||||
//"clear" link
|
||||
if(this.options.clear) {
|
||||
this.$clear = $('<a href="#"></a>').html(this.options.clear).click($.proxy(function(e){
|
||||
@@ -178,24 +205,41 @@ $(function(){
|
||||
},
|
||||
|
||||
autosubmit: function() {
|
||||
// Override default autosubmit behavior for datepicker workflow
|
||||
// Show buttons only after date selection
|
||||
this.$input.on('changeDate', $.proxy(function(e) {
|
||||
console.log('Date changeDate event triggered');
|
||||
// Hide the datepicker
|
||||
this.$input.datepicker('hide');
|
||||
// Show save/cancel buttons after date selection
|
||||
setTimeout($.proxy(function() {
|
||||
if (this.options.showbuttons !== false) {
|
||||
var $buttons = this.$form ? this.$form.find('.editable-buttons') : $();
|
||||
if ($buttons.length === 0) {
|
||||
$buttons = this.$tpl.closest('.editableform').find('.editable-buttons');
|
||||
}
|
||||
if ($buttons.length === 0) {
|
||||
$buttons = this.$tpl.closest('.editable-container').find('.editable-buttons');
|
||||
}
|
||||
|
||||
console.log('Date changeDate: Found buttons to show:', $buttons.length);
|
||||
$buttons.show();
|
||||
$buttons.css('display', 'inline-block');
|
||||
}
|
||||
}, this), 100);
|
||||
}, this));
|
||||
|
||||
// Keep the original click behavior as backup
|
||||
this.$input.on('mouseup', '.day', function(e){
|
||||
if($(e.currentTarget).is('.old') || $(e.currentTarget).is('.new')) {
|
||||
return;
|
||||
}
|
||||
console.log('Date mouseup on day');
|
||||
var $form = $(this).closest('form');
|
||||
setTimeout(function() {
|
||||
$form.submit();
|
||||
$form.find('.editable-buttons').show();
|
||||
}, 200);
|
||||
});
|
||||
//changedate is not suitable as it triggered when showing datepicker. see #149
|
||||
/*
|
||||
this.$input.on('changeDate', function(e){
|
||||
var $form = $(this).closest('form');
|
||||
setTimeout(function() {
|
||||
$form.submit();
|
||||
}, 200);
|
||||
});
|
||||
*/
|
||||
},
|
||||
|
||||
/*
|
||||
|
@@ -33,12 +33,36 @@ Automatically shown in inline mode.
|
||||
//need to disable original event handlers
|
||||
this.$input.off('focus keydown');
|
||||
|
||||
// Hide buttons initially for datepicker workflow
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
if (!self.$form) {
|
||||
// Find buttons in the broader DOM and hide them directly
|
||||
var $allButtons = $('.editable-buttons:visible');
|
||||
if ($allButtons.length > 0) {
|
||||
$allButtons.each(function(i, btn) {
|
||||
// Directly hide this button for datepicker
|
||||
var $btn = $(btn);
|
||||
$btn.hide();
|
||||
$btn.css('display', 'none !important');
|
||||
$btn.addClass('datepicker-hidden');
|
||||
|
||||
// Store reference for later showing
|
||||
self.$dateButtons = $btn;
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
|
||||
//update value of datepicker
|
||||
this.$input.keyup($.proxy(function(){
|
||||
this.$tpl.removeData('date');
|
||||
this.$tpl.datepicker('update');
|
||||
}, this));
|
||||
|
||||
// Manually call autosubmit to set up our event handlers
|
||||
this.autosubmit();
|
||||
|
||||
},
|
||||
|
||||
value2input: function(value) {
|
||||
@@ -86,7 +110,61 @@ Automatically shown in inline mode.
|
||||
},
|
||||
|
||||
autosubmit: function() {
|
||||
//reset autosubmit to empty
|
||||
// Override default autosubmit behavior for datepicker workflow
|
||||
// We handle this manually with changeDate event
|
||||
|
||||
// Setup the manual workflow: show buttons only after date selection
|
||||
this.$tpl.on('changeDate', $.proxy(function(e) {
|
||||
// Hide the datepicker using multiple methods to ensure it closes
|
||||
setTimeout($.proxy(function() {
|
||||
// Try datepicker hide methods
|
||||
try {
|
||||
this.$tpl.datepicker('hide');
|
||||
} catch(err) {
|
||||
// Fallback to input method
|
||||
}
|
||||
|
||||
try {
|
||||
this.$input.datepicker('hide');
|
||||
} catch(err) {
|
||||
// Continue to force methods
|
||||
}
|
||||
|
||||
// Force hide all datepicker elements
|
||||
$('.datepicker').hide();
|
||||
$('.datepicker-dropdown').hide();
|
||||
|
||||
// Ensure any remaining visible datepickers are hidden
|
||||
var $visiblePicker = $('.datepicker:visible, .datepicker-dropdown:visible');
|
||||
if ($visiblePicker.length > 0) {
|
||||
$visiblePicker.css('display', 'none !important');
|
||||
$visiblePicker.css('visibility', 'hidden');
|
||||
}
|
||||
}, this), 10);
|
||||
|
||||
// Show save/cancel buttons after date selection
|
||||
setTimeout($.proxy(function() {
|
||||
if (this.options.showbuttons !== false) {
|
||||
var $buttons = this.$dateButtons || $('.editable-buttons.datepicker-hidden');
|
||||
if ($buttons.length === 0) {
|
||||
$buttons = this.$form ? this.$form.find('.editable-buttons') : $();
|
||||
}
|
||||
if ($buttons.length === 0) {
|
||||
$buttons = this.$tpl.closest('.editableform').find('.editable-buttons');
|
||||
}
|
||||
if ($buttons.length === 0) {
|
||||
$buttons = this.$tpl.closest('.editable-container').find('.editable-buttons');
|
||||
}
|
||||
|
||||
$buttons.show();
|
||||
$buttons.css('display', 'inline-flex');
|
||||
$buttons.addClass('show-buttons');
|
||||
$buttons.removeClass('datepicker-hidden');
|
||||
}
|
||||
}, this), 100);
|
||||
}, this));
|
||||
|
||||
// Do NOT call parent autosubmit to prevent immediate form submission
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user