Skip to content

Commit

Permalink
Fix datetime fields not showing inline picker
Browse files Browse the repository at this point in the history
  • Loading branch information
rilwis committed Dec 23, 2024
1 parent 62ed3e8 commit 872dbd0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
25 changes: 15 additions & 10 deletions js/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
* Transform an input into a date picker.
*/
function transform() {
var $this = $( this ),
options = $this.data( 'options' ),
$inline = $this.siblings( '.rwmb-datetime-inline' ),
$timestamp = $this.siblings( '.rwmb-datetime-timestamp' ),
let $this = $( this ),
options = $this.data( 'options' );

let $inline = $this.siblings( '.rwmb-datetime-inline' );
if ( !$inline.length ) {
$inline = $this.closest( '.rwmb-input-group' ).siblings( '.rwmb-datetime-inline' );
}

let $timestamp = $this.siblings( '.rwmb-datetime-timestamp' ),
current = $this.val(),
$picker = $inline.length ? $inline : $this;

$this.siblings( '.ui-datepicker-append' ).remove(); // Remove appended text

options.onSelect = function() {
options.onSelect = function () {
$this.trigger( 'change' );
}
options.beforeShow = function( i ) {
};
options.beforeShow = function ( i ) {
if ( $( i ).prop( 'readonly' ) ) {
return false;
}
}
};

if ( $timestamp.length ) {
options.onClose = options.onSelect = function () {
Expand All @@ -36,15 +41,15 @@
} );
}

if ( ! $inline.length ) {
if ( !$inline.length ) {
$this.removeClass( 'hasDatepicker' ).datepicker( options );
return;
}

options.altField = '#' + $this.attr( 'id' );
$this.on( 'keydown', _.debounce( function () {
// if val is empty, return to allow empty datepicker input.
if ( ! $this.val() ) {
if ( !$this.val() ) {
return;
}
$picker
Expand Down
29 changes: 17 additions & 12 deletions js/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
* Transform an input into a datetime picker.
*/
function transform() {
var $this = $( this ),
options = $this.data( 'options' ),
$inline = $this.siblings( '.rwmb-datetime-inline' ),
$timestamp = $this.siblings( '.rwmb-datetime-timestamp' ),
let $this = $( this ),
options = $this.data( 'options' );

let $inline = $this.siblings( '.rwmb-datetime-inline' );
if ( !$inline.length ) {
$inline = $this.closest( '.rwmb-input-group' ).siblings( '.rwmb-datetime-inline' );
}

let $timestamp = $this.siblings( '.rwmb-datetime-timestamp' ),
current = $this.val(),
$picker = $inline.length ? $inline : $this;

$this.siblings( '.ui-datepicker-append' ).remove(); // Remove appended text

options.onSelect = function() {
options.onSelect = function () {
$this.trigger( 'change' );
}
options.beforeShow = function( i ) {
};
options.beforeShow = function ( i ) {
if ( $( i ).prop( 'readonly' ) ) {
return false;
}
}
};

if ( $timestamp.length ) {
options.onClose = options.onSelect = function () {
Expand All @@ -36,15 +41,15 @@
} );
}

if ( ! $inline.length ) {
if ( !$inline.length ) {
$this.removeClass( 'hasDatepicker' ).datetimepicker( options );
return;
}

options.altField = '#' + $this.attr( 'id' );
$this.on( 'keydown', _.debounce( function () {
// if val is empty, return to allow empty datepicker input.
if ( ! $this.val() ) {
if ( !$this.val() ) {
return;
}
$picker
Expand Down Expand Up @@ -78,9 +83,9 @@
// Set language if available
function setTimeI18n() {
if ( $.timepicker.regional.hasOwnProperty( i18n.locale ) ) {
$.timepicker.setDefaults( $.timepicker.regional[i18n.locale] );
$.timepicker.setDefaults( $.timepicker.regional[ i18n.locale ] );
} else if ( $.timepicker.regional.hasOwnProperty( i18n.localeShort ) ) {
$.timepicker.setDefaults( $.timepicker.regional[i18n.localeShort] );
$.timepicker.setDefaults( $.timepicker.regional[ i18n.localeShort ] );
}
}

Expand Down
7 changes: 5 additions & 2 deletions js/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* Transform an input into a time picker.
*/
function transform() {
var $this = $( this ),
let $this = $( this ),
options = $this.data( 'options' ),
$inline = $this.siblings( '.rwmb-datetime-inline' ),
current = $this.val();
current = formatTime( current );

Expand All @@ -22,6 +21,10 @@
}
};

let $inline = $this.siblings( '.rwmb-datetime-inline' );
if ( !$inline.length ) {
$inline = $this.closest( '.rwmb-input-group' ).siblings( '.rwmb-datetime-inline' );
}
if ( !$inline.length ) {
$this.removeClass( 'hasDatepicker' ).timepicker( options ).timepicker( 'setTime', current );
return;
Expand Down

0 comments on commit 872dbd0

Please sign in to comment.