@@ -62,54 +62,60 @@ prplDocumentReady( () => {
6262 'input[name="date_format_custom"]'
6363 ) ;
6464
65- customDateInput . addEventListener ( 'click' , function ( ) {
66- document . getElementById ( 'date_format_custom_radio' ) . checked = true ;
67- } ) ;
65+ if ( customDateInput ) {
66+ customDateInput . addEventListener ( 'click' , function ( ) {
67+ document . getElementById (
68+ 'date_format_custom_radio'
69+ ) . checked = true ;
70+ } ) ;
6871
69- customDateInput . addEventListener ( 'input' , function ( ) {
70- document . getElementById ( 'date_format_custom_radio' ) . checked = true ;
72+ customDateInput . addEventListener ( 'input' , function ( ) {
73+ document . getElementById (
74+ 'date_format_custom_radio'
75+ ) . checked = true ;
7176
72- const format = this ;
73- const fieldset = format . closest ( 'fieldset' ) ;
74- const example = fieldset . querySelector ( '.example' ) ;
77+ const format = this ;
78+ const fieldset = format . closest ( 'fieldset' ) ;
79+ const example = fieldset . querySelector ( '.example' ) ;
7580
76- // Debounce the event callback while users are typing.
77- clearTimeout ( format . dataset . timer ) ;
78- format . dataset . timer = setTimeout ( function ( ) {
79- // If custom date is not empty.
80- if ( format . value ) {
81- // Find the spinner element within the fieldset
82- const spinner = fieldset . querySelector ( '.spinner' ) ;
83- if ( spinner ) {
84- spinner . classList . add ( 'is-active' ) ;
85- }
81+ // Debounce the event callback while users are typing.
82+ clearTimeout ( format . dataset . timer ) ;
83+ format . dataset . timer = setTimeout ( function ( ) {
84+ // If custom date is not empty.
85+ if ( format . value ) {
86+ // Find the spinner element within the fieldset
87+ const spinner = fieldset . querySelector ( '.spinner' ) ;
88+ if ( spinner ) {
89+ spinner . classList . add ( 'is-active' ) ;
90+ }
8691
87- // Use fetch instead of $.post
88- fetch ( progressPlanner . ajaxUrl , {
89- method : 'POST' ,
90- headers : {
91- 'Content-Type' : 'application/x-www-form-urlencoded' ,
92- } ,
93- body : new URLSearchParams ( {
94- action : 'date_format' ,
95- date : format . value ,
96- } ) ,
97- } )
98- . then ( function ( response ) {
99- return response . text ( ) ;
100- } )
101- . then ( function ( data ) {
102- example . textContent = data ;
92+ // Use fetch instead of $.post
93+ fetch ( progressPlanner . ajaxUrl , {
94+ method : 'POST' ,
95+ headers : {
96+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
97+ } ,
98+ body : new URLSearchParams ( {
99+ action : 'date_format' ,
100+ date : format . value ,
101+ } ) ,
103102 } )
104- . catch ( function ( error ) {
105- console . error ( 'Error:' , error ) ;
106- } )
107- . finally ( function ( ) {
108- if ( spinner ) {
109- spinner . classList . remove ( 'is-active' ) ;
110- }
111- } ) ;
112- }
113- } , 500 ) ;
114- } ) ;
103+ . then ( function ( response ) {
104+ return response . text ( ) ;
105+ } )
106+ . then ( function ( data ) {
107+ example . textContent = data ;
108+ } )
109+ . catch ( function ( error ) {
110+ console . error ( 'Error:' , error ) ;
111+ } )
112+ . finally ( function ( ) {
113+ if ( spinner ) {
114+ spinner . classList . remove ( 'is-active' ) ;
115+ }
116+ } ) ;
117+ }
118+ } , 500 ) ;
119+ } ) ;
120+ }
115121} ) ;
0 commit comments