PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
← All changes | includes/_feedback_deactivation/_src/feedback.js +72 -7 11.211.8.3 View file →
@@ -57,18 +57,66 @@
57 57
58 58 $( 'input.wpbc_deactivate-feedback-input' ).on(
59 59 'click',
60 60 function () {
61 - if ( jQuery( "form.wpbc_deactivate-feedback-form" ).find( 'input[name="reason_slug"]:checked' ).length ) {
62 - jQuery( '.wpbc_deactivate-feedback-popup-form-more-details' ).show();
63 - jQuery( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).hide();
64 - } else {
65 - jQuery( '.wpbc_deactivate-feedback-popup-form-more-details' ).hide();
66 - jQuery( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).show();
61 + _that.set_more_details_state( jQuery( "form.wpbc_deactivate-feedback-form" ) );
62 + }
63 + );
64 +
65 + $( '#wpbc_deactivate-feedback-popup-wrapper' ).on(
66 + 'input',
67 + '.feedback-textarea',
68 + function () {
69 + if ( '' !== jQuery.trim( jQuery( this ).val() ) ) {
70 + _that.clear_more_details_error( jQuery( this ).closest( 'form.wpbc_deactivate-feedback-form' ) );
67 71 }
68 72 }
69 73 );
70 74 },
75 + set_more_details_state: function (form) {
76 + var has_selected_reason = form.find( 'input[name="reason_slug"]:checked' ).length > 0;
77 + var details_wrap = form.find( '.wpbc_deactivate-feedback-popup-form-more-details' );
78 + var details_field = details_wrap.find( '.feedback-textarea' );
79 +
80 + if ( has_selected_reason ) {
81 + details_wrap.show();
82 + details_field.prop( 'required', true );
83 + form.find( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).hide();
84 + } else {
85 + details_wrap.hide();
86 + details_field.prop( 'required', false ).val( '' );
87 + form.find( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).show();
88 + this.clear_more_details_error( form );
89 + }
90 + },
91 + clear_more_details_error: function (form) {
92 + form.find( '.feedback-textarea' ).attr( 'aria-invalid', 'false' );
93 + form.find( '.wpbc_deactivate-feedback-more-details-error' ).hide();
94 + },
95 + show_more_details_error: function (form, message) {
96 + var details_field = form.find( '.feedback-textarea' );
97 + form.find( '.wpbc_deactivate-feedback-more-details-error' ).text( message ).show();
98 + details_field.attr( 'aria-invalid', 'true' ).trigger( 'focus' );
99 + },
100 + validate_more_details: function (form) {
101 + var details_wrap = form.find( '.wpbc_deactivate-feedback-popup-form-more-details' );
102 + var details_field = details_wrap.find( '.feedback-textarea' );
103 + var message = (
104 + 'undefined' !== typeof wpbc_plugins_params &&
105 + 'undefined' !== typeof wpbc_plugins_params.more_details_required_text
106 + ) ? wpbc_plugins_params.more_details_required_text : 'Please share more details before submitting.';
107 +
108 + if ( details_wrap.is( ':visible' ) && '' === jQuery.trim( details_field.val() ) ) {
109 + this.show_more_details_error( form, message );
110 + return false;
111 + }
112 +
113 + this.clear_more_details_error( form );
114 + return true;
115 + },
116 + enable_submit: function (form) {
117 + form.find( "button.submit" ).removeClass( "button-disabled button updating-message" );
118 + },
71 119 send_data: function (form) {
72 120 var reason_slug = form.find( 'input[name="reason_slug"]:checked' ).map(
73 121 function () {
74 122 return jQuery( this ).val();
@@ -79,8 +127,12 @@
79 127 alert( "Please select at least one option from the list" );
80 128 return;
81 129 }
82 130
131 + if ( ! this.validate_more_details( form ) ) {
132 + return;
133 + }
134 +
83 135 if ( form.find( "button.submit" ).hasClass( "button-disabled" ) ) {
84 136 return;
85 137 }
86 138
@@ -122,10 +174,23 @@
122 174 );
123 175 },
124 176 }
125 177 ).done(
178 + function (response) {
179 + if ( response && response.success ) {
180 + window.location = form.find( "a.skip" ).attr( "href" );
181 + return;
182 + }
183 +
184 + _that.enable_submit( form );
185 + _that.show_more_details_error(
186 + form,
187 + response && response.data && response.data.message ? response.data.message : 'Please share more details before submitting.'
188 + );
189 + }
190 + ).fail(
126 191 function () {
127 - window.location = form.find( "a.skip" ).attr( "href" );
192 + _that.enable_submit( form );
128 193 }
129 194 );
130 195 },
131 196 };