1( function( $ ) { 2 /** 3 * @param $scope The Widget wrapper element as a jQuery element 4 * @param $ The jQuery alias 5 */ 6 var WidgetSolaceformHandler = function( $scope, $ ) { 7 const form = $scope.find( '.solaceform-form' ); 8 const post_id = form.data( 'post_id' ); 9 const post_id2 = $( '.solace-custom-header-footer').attr('post-id'); 10 const el_id = form.data( 'el_id' ); 11 const msg_form = $scope.find( '.solaceform-form-msg span' ); 12 let extension = ''; 13 $( '.solaceform-form input[type="file"]' ).each( function () { 14 extension = $(this).attr( 'accept' ); 15 }); 16 17 // Handle checkbox required attribute logic 18 form.on('change', 'input[type="checkbox"][data-required="true"]', function() { 19 const $currentCheckbox = $(this); 20 const $checkboxWarp = $currentCheckbox.closest('.solaceform-checkbox-warp'); 21 22 // Only proceed if we're in a .solaceform-checkbox-warp container 23 if ($checkboxWarp.length > 0) { 24 const isChecked = $currentCheckbox.is(':checked'); 25 26 if (isChecked) { 27 // When a required checkbox is checked, remove required from all other checkboxes in the same container 28 $checkboxWarp.find('input[type="checkbox"]').not($currentCheckbox).removeAttr('required'); 29 } else { 30 // When a required checkbox is unchecked, add required back to all other required checkboxes in the same container 31 $checkboxWarp.find('input[type="checkbox"][data-required="true"]').not($currentCheckbox).attr('required', 'required'); 32 } 33 } 34 }); 35 36 form.on( 'submit', function(e) { 37 e.preventDefault(); 38 39 const formDataSerialize = form.serialize(); 40 41 // Parse serialized form data into an object 42 const urlParams = new URLSearchParams(formDataSerialize); 43 let msg_email = ''; 44 45 // // Convert URLSearchParams to an object 46 // urlParams.forEach((value, key) => { 47 // msg_email += key + ': ' + value + '<br/><br/>'; 48 // }); 49 50 form.find('input, textarea, select').each(function() { 51 const el = $(this); 52 53 // Get the custom label from `get_label` attribute 54 const label = el.attr('get_label'); 55 const value = el.val(); 56 57 // Skip radio/checkbox if they are not checked 58 if ((el.is(':radio') || el.is(':checkbox')) && !el.is(':checked')) { 59 return; // Important: avoid unselected radios/checkboxes 60 } 61 62 // Append label and value to the email message string 63 // For input type="number", this works the same as text 64 if ( label ) { 65 msg_email += label + ': ' + value + '<br/><br/>'; 66 } else { 67 msg_email += value + '<br/><br/>'; 68 } 69 }); 70 71 const formData = new FormData(form[0]); 72 73 // Add additional data to FormData 74 formData.append('action', 'elementor_form_builder_form_ajax'); 75 formData.append('post_id', post_id); 76 formData.append('post_id2', post_id2); 77 formData.append('el_id', el_id); 78 formData.append('nonce', elementor_form_builder_obj.nonce); 79 formData.append('dataSerialize', msg_email); 80 formData.append('extension', extension); 81 82 // Add class active 83 $( '.solaceform-form-button' ).addClass( 'active' ).prop('disabled', true); 84 85 $.ajax({ 86 method: 'POST', 87 url: elementor_form_builder_obj.ajaxurl, 88 data: formData, 89 processData: false, // Prevent jQuery from processing the data 90 contentType: false, // Let the browser set the correct content type 91 success: function(res) { 92 if ( res.success ) { 93 msg_form.text(res.data.success_message); 94 msg_form.css({ 95 'color': '#05b705', 96 'margin-top': '5px', 97 'display': 'block', 98 }); 99 $( '.solaceform-form-msg' ).fadeIn( 300 ); 100 } else { 101 msg_form.text(res.data.error_message); 102 msg_form.css({ 103 'color': '#f72929', 104 'margin-top': '5px', 105 'display': 'block', 106 }); 107 $( '.solaceform-form-msg' ).fadeIn( 300 ); 108 } 109 110 // Clear all form input values 111 form.find('input, textarea, select').val('') 112 .prop('checked', false) // Uncheck checkboxes and radios 113 .prop('selected', false); // Deselect options in select dropdowns 114 115 // remove class active 116 $( '.solaceform-form-button' ).removeClass( 'active' ).prop('disabled', false); 117 118 }, 119 error: function(err) { 120 const errorData = JSON.parse(err.responseText); 121 const errorMessage = errorData?.data?.error_message; 122 123 msg_form.text(errorMessage); 124 msg_form.css({ 125 'color': '#f72929', 126 'margin-top': '5px', 127 'display': 'block', 128 }); 129 $( '.solaceform-form-msg' ).fadeIn( 300 ); 130 131 // remove class active 132 $( '.solaceform-form-button' ).removeClass( 'active' ).prop('disabled', false); 133 } 134 }); 135 }); 136 }; 137 138 139 $( window ).on( 140 'elementor/frontend/init', 141 function() { 142 elementorFrontend.hooks.addAction( 'frontend/element_ready/solaceform.default', WidgetSolaceformHandler ) 143 } 144 ) 145} )( jQuery )
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.