1import { useEffect, useState, useCallback } from '@wordpress/element'; 2import { __ } from '@wordpress/i18n'; 3import React from 'react'; 4 5const get_field_detail = php_array.get_field_detail; 6 7// const recaptcha_setting = php_array.recaptcha_setting; 8var checkout_fields_heading = ''; 9if(get_field_detail.length > 0 ){ 10 checkout_fields_heading = php_array.recaptcha_setting.title; 11} 12 13export const Block = ({ checkoutExtensionData }) => { 14 15 const [inputvalues, Set_Field_Values] = useState({}); 16 const [multicheckbox_and_radio, Set_multicheckbox_and_radio_Field_Values] = useState({}); 17 18 const { setExtensionData } = checkoutExtensionData; 19 20 21 // useEffect(() => { 22 23 // },); 24 25 useEffect(() => { 26 27 const script = document.createElement('script'); 28 script.src = 'https://www.google.com/recaptcha/api.js'; 29 script.async = true; 30 script.defer = true; 31 document.body.appendChild(script); 32 33 },); 34 35 const handleBlur = () => { 36 37 setTimeout(hide_show_using_dependablilities, 3000); 38 39 40 }; 41 42 43 // calling for dependentiblity check for multiselect 44 jQuery('.af-afreg_add_select2').on('change', function (event) { 45 set_value_on_multiselect_and_radio(event); 46 }); 47 48 // const set_value_on_multiselect_and_radio = (field_name, value, event) => { 49 50 const set_value_on_multiselect_and_radio = (event) => { 51 52 let current_event_id = event.target.id; 53 let current_event_type = event.target.type; 54 let field_name = event.target.name; 55 let element_type = event.target.tagName.toLowerCase(); // This will give you 'input', 'select', etc. 56 57 let extr_attr = ''; 58 59 if ('radio' == current_event_type || 'checkbox' == current_event_type) { 60 extr_attr = extr_attr + ':checked'; 61 } 62 var select_value = ''; 63 64 if (element_type === 'select' && event.target.multiple) { 65 jQuery('select#' + current_event_id + ' option:selected').each(function () { 66 67 select_value += ',' + jQuery(this).val(); 68 }); 69 70 } else if (element_type === 'input' && current_event_type === 'checkbox' && event.target.multiple) { 71 72 73 jQuery(`input[name="${field_name}"]:checked`).each(function () { 74 75 select_value += ',' + jQuery(this).val(); 76 }); 77 78 } else { 79 select_value = jQuery('#' + current_event_id + extr_attr).val(); 80 } 81 82 // Assuming setExtensionData is a function to store the values 83 setExtensionData('addify_user_registration_field', field_name, select_value); 84 85 hide_show_using_dependablilities(); 86 87 }; 88 89 90 return ( 91 <> 92 <div className="af-urf-blocks-main-div "> 93 < div key="af_urf_main_title"> 94 <div className="af-urg-checkout-blocks" > 95 96 <h4> 97 {checkout_fields_heading} 98 </h4> 99 <div className="g-checkout_fields_heading" ></div> 100 </div> 101 </div> 102 {get_field_detail.map((field_details, key) => ( 103 104 < div key={key} className={`af-urg-checkout-blocks af-urg-dependable-field-main-div-blocks af-urg-checkout-blocks${field_details.current_field_id ? field_details.current_field_id : key} ${field_details.afreg_main_class ? field_details.afreg_main_class : ''}`} 105 {...(field_details.dependable_field_detail 106 ? Object.entries(field_details.dependable_field_detail).reduce((acc, [attrKey, attrValue]) => { 107 acc[attrKey] = attrValue; 108 109 return acc; 110 }, {}) 111 : {})} 112 > 113 114 {field_details.type && (('number text tel email checkbox color date time password').indexOf(field_details.type) !== -1) && ( 115 <> 116 117 <div> 118 <div class="wc-block-components-checkout-step__heading"> 119 <h2 class="wc-block-components-title wc-block-components-checkout-step__title" aria-hidden="true">{field_details.field_label ? field_details.field_label : ''}</h2>
120 <span class="wc-block-components-checkout-step__heading-content"></span> 121 </div> 122 <div class="wc-block-components-checkout-step__container"> 123 <p class="wc-block-components-checkout-step__description"></p> 124 <div class="wc-block-components-checkout-step__content"> 125 <div class="wc-block-components-notices"></div> 126 <div class="wc-block-components-notices__snackbar wc-block-components-notice-snackbar-list" tabindex="-1"> 127 <div></div> 128 </div> 129 <div id="contact" class="wc-block-components-address-form"> 130 131 <div class="wc-block-components-text-input wc-block-components-address-form__email is-active"> 132 <input 133 type={field_details.type} 134 name={field_details.field_name} 135 value={'checkbox' == field_details.type ? 'yes' : inputvalues[field_details.field_name]} 136 id={field_details.id} 137 className={`af-ure-check-dependable-fields ${field_details.class}`} 138 placeholder={field_details.afreg_field_placeholder} 139 onInput={(e) => set_value_on_multiselect_and_radio(e)} 140 onKeyUp={(e) => set_value_on_multiselect_and_radio(e)} 141 onKeyDown={(e) => set_value_on_multiselect_and_radio(e)} 142 onFocus={(e) => set_value_on_multiselect_and_radio(e)} 143 onBlur={handleBlur} 144 {...Object.keys(field_details.data || {}).reduce((acc, dataKey) => { 145 acc[`data-${dataKey}`] = field_details.data[dataKey]; 146 return acc; 147 }, {})} 148 /> 149 </div> 150 151 <div 152 style={{ display: 'none' }} 153 className={`wc-block-components-validation-error af_reg_block_error_${field_details.field_name}`} 154 role="alert" 155 > 156 <p id="validate-error-shipping_first_name"> 157 <svg 158 xmlns="http://www.w3.org/2000/svg"
159 viewBox="-2 -2 24 24" 160 width="24" 161 height="24" 162 aria-hidden="true" 163 focusable="false" 164 > 165 <path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1.13 9.38l.35-6.46H8.52l.35 6.46h2.26zm-.09 3.36c.24-.23.37-.55.37-.96 0-.42-.12-.74-.36-.97s-.59-.35-1.06-.35-.82.12-1.07.35-.37.55-.37.97c0 .41.13.73.38.96.26.23.61.34 1.06.34s.8-.11 1.05-.34z"></path> 166 </svg> 167 <span>Required Field</span> 168 </p> 169 </div> 170 171 </div> 172 </div> 173 </div> 174 </div> 175 </> 176 ) 177 } 178 {field_details.type && (('textarea').indexOf(field_details.type) !== -1) && ( 179 <> 180 181 <div> 182 <div class="wc-block-components-checkout-step__heading"> 183 184 <h2 class="wc-block-components-title wc-block-components-checkout-step__title" aria-hidden="true">{field_details.field_label ? field_details.field_label : ''}</h2> 185 <span class="wc-block-components-checkout-step__heading-content"></span> 186 </div> 187 <div class="wc-block-components-checkout-step__container"> 188 <p class="wc-block-components-checkout-step__description"></p> 189 <div class="wc-block-components-checkout-step__content"> 190 <div class="wc-block-components-notices"></div> 191 <div class="wc-block-components-notices__snackbar wc-block-components-notice-snackbar-list" tabindex="-1"> 192 <div></div> 193 </div> 194 <div id="contact" class="wc-block-components-address-form"> 195 <div class="wc-block-components-text-input wc-block-components-address-form__email is-active"> 196 <textarea 197 name={field_details.field_name} 198 value={'checkbox' == field_details.type ? 'yes' : inputvalues[field_details.field_name]} 199 id={field_details.id} 200 className={`af-ure-check-dependable-fields af_reg_textara ${field_details.class}`} 201 placeholder={field_details.afreg_field_placeholder} 202 onInput={(e) => set_value_on_multiselect_and_radio(e)} 203 onKeyUp={(e) => set_value_on_multiselect_and_radio(e)} 204 onKeyDown={(e) => set_value_on_multiselect_and_radio(e)} 205 onFocus={(e) => set_value_on_multiselect_and_radio(e)} 206 onBlur={handleBlur} 207 {...Object.keys(field_details.data || {}).reduce((acc, dataKey) => { 208 acc[`data-${dataKey}`] = field_details.data[dataKey]; 209 return acc; 210 }, {})} 211 ></textarea> 212 </div> 213 214 <div 215 style={{ display: 'none' }} 216 className={`wc-block-components-vali
216dation-error af_reg_block_error_${field_details.field_name}`} 217 role="alert" 218 > 219 <p id="validate-error-shipping_first_name"> 220 <svg 221 xmlns="http://www.w3.org/2000/svg" 222 viewBox="-2 -2 24 24" 223 width="24" 224 height="24" 225 aria-hidden="true" 226 focusable="false" 227 > 228 <path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1.13 9.38l.35-6.46H8.52l.35 6.46h2.26zm-.09 3.36c.24-.23.37-.55.37-.96 0-.42-.12-.74-.36-.97s-.59-.35-1.06-.35-.82.12-1.07.35-.37.55-.37.97c0 .41.13.73.38.96.26.23.61.34 1.06.34s.8-.11 1.05-.34z"></path> 229 </svg> 230 <span>Required Field</span> 231 </p> 232 </div> 233 </div> 234 </div> 235 </div> 236 </div> 237 </> 238 ) 239 } 240 {field_details.options && field_details.type && (('select multiselect').indexOf(field_details.type) !== -1) && ( 241 <> 242 <div class="wc-block-components-checkout-step__heading"> 243 <h2 class="wc-block-components-title wc-block-components-checkout-step__title" aria-hidden="true">{field_details.field_label ? field_details.field_label : ''}</h2> 244 </div> 245 <div class="wc-block-components-checkout-step__container"> 246 <p class="wc-block-components-checkout-step__description"></p> 247 <div class="wc-block-components-checkout-step__content"> 248 <div class="wc-block-components-notices"></div> 249 <div class="wc-block-components-notices__snackbar wc-block-components-notice-snackbar-list" tabindex="-1"> 250 <div></div> 251 </div> 252 <div class="wc-block-components-address-address-wrapper is-editing"> 253 <div class="wc-block-components-address-card-wrapper"> 254 </div> 255 <div class="wc-block-components-address-form-wrapper"> 256 <div id="shipping" class="wc-block-components-address-form"> 257 <div class="wc-block-components-address-form__country wc-block-components-country-input"> 258 <div id="shipping-country" class="wc-block-components-combobox is-active"> 259 <div> 260 <select width="100%" 261 name={field_details.field_name} 262 id={field_details.id} 263 className={`af-afreg_add_select2 af-for_select2 af-ure-check-dependable-fields ${field_details.class} ${field_details.current_attr_common_classes_for} `} 264 placeholder={field_details.afreg_field_placeholder} 265 value={inputvalues[field_details.field_name]} 266 multiple={'multiselect' == field_details.type ? 'multiple' : ''} 267 {...Object.keys(field_details.data || {}).reduce((acc, dataKey) => { 268 acc[`data-${dataKey}`] = field_details.data[dataKey]; 269 return acc; 270 }, {})} 271 > 272 {Object.entries(field_details.options).map((option_detail, index) => ( 273 274 < option key={index} value={option_detail[0]} > 275 {option_detail[1]} 276 </option> 277 ))} 278 279 280 </select> 281 </div> 282 </div> 283 284 285 <div 286 style={{ display: 'none' }} 287 className={`wc-block-components-vali
287dation-error af_reg_block_error_${field_details.field_name}`} 288 role="alert" 289 > 290 <p id="validate-error-shipping_first_name"> 291 <svg 292 xmlns="http://www.w3.org/2000/svg" 293 viewBox="-2 -2 24 24" 294 width="24" 295 height="24" 296 aria-hidden="true" 297 focusable="false" 298 > 299 <path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1.13 9.38l.35-6.46H8.52l.35 6.46h2.26zm-.09 3.36c.24-.23.37-.55.37-.96 0-.42-.12-.74-.36-.97s-.59-.35-1.06-.35-.82.12-1.07.35-.37.55-.37.97c0 .41.13.73.38.96.26.23.61.34 1.06.34s.8-.11 1.05-.34z"></path> 300 </svg> 301 <span>Required Field</span> 302 </p> 303 </div> 304 305 </div> 306 </div> 307 </div> 308 </div> 309 </div> 310 </div> 311 </> 312 ) 313 } 314 {field_details.options && field_details.type && (('multi_checkbox radio').indexOf(field_details.type) !== -1) && ( 315 <> 316 <div class="wc-block-components-checkout-step__heading"><h2 class="wc-block-components-title wc-block-components-checkout-step__title" aria-hidden="true">{field_details.field_label ? field_details.field_label : ''}</h2></div> 317 <div class="wc-block-components-checkout-step__container"> 318 <div class="wc-block-components-checkout-step__content"> 319 320 <div class=""> 321 322 {Object.entries(field_details.options).map((option_detail, index) => ( 323 React.createElement( 324 'div', 325 { 326 key: key, 327 className: "wc-block-components-radio-control-accordion-option", 328 placeholder: field_details.afreg_field_placeholder, 329 330 }, 331 <> 332 333 <label className=""> 334 < input 335 key={key} 336 id={field_details.id} 337 value={option_detail[0]} 338 type={'multi_checkbox' == field_details.type ? 'checkbox' : field_details.type} 339 multiple={'multi_checkbox' == field_details.type ? true : false} 340 name={field_details.field_name} 341 className={`af-ure-check-dependable-fields ${field_details.class} ${field_details.field_name}`} 342 placeholder={field_details.afreg_field_placeholder} 343 onBlur={handleBlur} 344 onChange={(e) => set_value_on_multiselect_and_radio(e)} 345 {...Object.keys(field_details.data || {}).reduce((acc, dataKey) => { 346 acc[`data-${dataKey}`] = field_details.data[dataKey]; 347 return acc; 348 }, {})} 349 />
350 <span className='af_radio_label_bl'>{option_detail[1]}</span> 351 </label> 352 353 </> 354 ) 355 ))} 356 </div> 357 </div> 358 </div> 359 360 <div 361 style={{ display: 'none' }} 362 className={`wc-block-components-validation-error af_reg_block_error_${field_details.field_name}`} 363 role="alert" 364 > 365 <p id="validate-error-shipping_first_name"> 366 <svg 367 xmlns="http://www.w3.org/2000/svg"
368 viewBox="-2 -2 24 24" 369 width="24" 370 height="24" 371 aria-hidden="true" 372 focusable="false" 373 > 374 <path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1.13 9.38l.35-6.46H8.52l.35 6.46h2.26zm-.09 3.36c.24-.23.37-.55.37-.96 0-.42-.12-.74-.36-.97s-.59-.35-1.06-.35-.82.12-1.07.35-.37.55-.37.97c0 .41.13.73.38.96.26.23.61.34 1.06.34s.8-.11 1.05-.34z"></path> 375 </svg> 376 <span>Required Field</span> 377 </p> 378 </div> 379 </> 380 ) 381 } 382 {field_details.options && field_details.type && (('heading description').indexOf(field_details.type) !== -1) && ( 383 384 React.createElement( 385 field_details.type === 'heading' ? field_details.afreg_field_heading_type : 'label', 386 { 387 key: key, 388 className: `af-urg-checkout-blocks af-urg-checkout-blocks${field_details.id} ${field_details.class} ${field_details.main_div_class}`, 389 placeholder: field_details.afreg_field_placeholder, 390 ...Object.keys(field_details.data || {}).reduce((acc, dataKey) => { 391 acc[`data-${dataKey}`] = field_details.data[dataKey]; 392 return acc; 393 }, {}) 394 }, 395 <h2 className='wc-block-components-title wc-block-components-checkout-step__title'> 396 {field_details.field_label} 397 </h2> 398 ) 399 ) 400 } 401 <p className='afreg_field_description' >{'heading' != field_details.type ? field_details.afreg_field_description : ''}{'description' == field_details.type ? field_details.afreg_field_description_field : ''}</p> 402 </div > 403 ))} 404 </div > 405 </> 406 ) 407}; 408 409 410setTimeout(() => { 411 412 jQuery('.af-afreg_add_select2').select2(); 413}, 3000); 414 415jQuery(document).on('click', '.wc-block-checkout__create-account input', hide_show_using_dependablilities); 416 417jQuery(document).on('click', '.af-afreg-registration-field', function () { 418 jQuery(document).closest('.wc-block-components-notice-banner').remove(); 419}); 420 421setTimeout(hide_show_using_dependablilities, 3000); 422function hide_show_using_dependablilities() { 423 424 var selected_user_role = jQuery('#afreg_select_user_role').val(); 425 426 jQuery(document).on('change','#afreg_select_user_role',function(){ 427 hide_show_using_dependablilities(); 428 }) 429 430 jQuery('.af-urg-dependable-field-main-div-blocks').each(function () { 431 432 let current_field = jQuery(this); 433 let current_main_field = jQuery(this); 434 let current_field_id = current_field.data('current_field_id') || ''; 435 436 var show_or_not = true; 437 438 // setExtensionData('addify_user_registration_field', field_name, select_value); 439 440 if ((current_field.data('dependable_field_id') && current_field.data('dependable_field_id') != undefined) || (current_field.data('dependable_field_on_user_role') && current_field.data('dependable_field_on_user_role') != undefined)) { 441 442 let check_dependibilites = true; 443 444 while (check_dependibilites) { 445 446 let current_field_id = current_field.data('current_field_id') || ''; 447 let dependable_field_id = current_field.data('dependable_field_id') || ''; 448 let dependable_field_option = current_field.data('dependable_field_option') || ''; 449 let dependable_field_on_user_role = current_field.data('dependable_field_on_user_role') || ''; 450 451 let dependable_field_value = af_urf_get_field_value(jQuery('#afreg_additionalshowhide_blocks_' + depen
451dable_field_id)); 452 453 // Ensure dependable_field_value is not undefined or empty. 454 dependable_field_value = (typeof dependable_field_value !== 'undefined' && dependable_field_value !== '') ? dependable_field_value : ''; 455 456 if (dependable_field_id && dependable_field_id != undefined) { 457 458 459 if (dependable_field_option) { 460 461 dependable_field_option = dependable_field_option.split(','); 462 463 464 if (!dependable_field_value || undefined == dependable_field_value) { 465 466 //debug point false 467 show_or_not = false; 468 469 } 470 471 if ('array' == typeof dependable_field_value || 'object' == typeof dependable_field_value) { 472 473 const matchFound = dependable_field_value.some(value => dependable_field_option.includes(value)); 474 475 476 if (!matchFound) { 477 478 //debug point false 479 show_or_not = false; 480 481 482 } 483 484 } else if (!dependable_field_option.includes(dependable_field_value)) { 485 486 show_or_not = false; 487 } 488 489 } else if (!jQuery('#afreg_additionalshowhide_blocks_' + dependable_field_id).is(':visible')) {; 490 491 show_or_not = false; 492 } 493 494 } 495 496 if (selected_user_role && dependable_field_on_user_role && dependable_field_on_user_role != undefined) { 497 498 dependable_field_on_user_role = dependable_field_on_user_role.split(","); 499 500 const matchFound = dependable_field_on_user_role.some(value => selected_user_role.includes(value)); 501 502 if (!show_or_not || (!dependable_field_id && !dependable_field_on_user_role)) { 503 504 break; 505 506 } 507 if (!dependable_field_on_user_role.includes(selected_user_role)) { 508 509 show_or_not = false; 510 break; 511 512 } 513 514 if (!matchFound) { 515 516 show_or_not = false; 517 break; 518 519 } else if (show_or_not) { 520 521 if (dependable_field_id && jQuery('.af-urg-checkout-blocks' + dependable_field_id).length) { 522 523 if (!jQuery('.af-urg-checkout-blocks' + dependable_field_id).data('dependable_field_on_user_role') && !jQuery('.af-urg-checkout-blocks' + dependable_field_id).data('dependable_field_id')) { 524 break; 525 526 } 527 528 } else { 529 break; 530 531 } 532 533 } 534 535 if (!show_or_not) { 536 537 break; 538 539 } 540 541 } 542 543 if (!dependable_field_on_user_role && !dependable_field_id) { 544 545 check_dependibilites = false; 546 547 } 548 549 if (dependable_field_id) { 550 current_field = jQuery('.af-urg-checkout-blocks' + dependable_field_id); 551 } 552 553 554 if (!show_or_not) { 555 556 break; 557 } 558 559 } 560 } 561 562 563 jQuery(this).removeClass('has-error'); 564 565 if (show_or_not) { 566 567 jQuery(this).show('slow'); 568 569 } else { 570 jQuery(this).hide('fast'); 571 572 } 573 574 }); 575 576 if (jQuery('.wc-block-checkout__create-account input[type=checkbox]').is(':checked')) { 577 jQuery('.af-urf-blocks-main-div').show(); 578 } else { 579 jQuery('.af-urf-blocks-main-div').hide(); 580 } 581 582} 583 584function get_error_html() { 585 return `<div class="wc-block-store-notice wc-block-components-notice-banner is-error is-dismissible"> 586 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"> 587 <path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path> 588 </svg> 589 <div class="wc-block-components-notice-banner__content"><div> - is required Field </div></div> 590 <button class="wc-block-components-button wp-element-button wc-block-components-notice-banner__dismiss contained" aria-label="Dismiss this notice" type="button"> 591 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"> 592 <path class="af-afreg-registration-field" d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path> 593 </svg> 594 </button> 595 </div>`; 596} 597function af_urf_get_field_value(event) { 598 599 600 if (!event.prop("id")) { 601 return ''; 602 }
603 let current_event_id = event.prop("id"); 604 let element_type = (event.prop("tagName")).toLowerCase(); // This will give you 'input', 'select', etc. 605 606 let current_event_type = event.prop("type"); // Using .prop() for type 607 608 609 let extr_attr = ''; 610 if ('radio' == current_event_type || 'checkbox' == current_event_type) { 611 extr_attr = extr_attr + ':checked'; 612 } 613 614 615 if (element_type === 'select' && event.multiple) { 616 617 var select_value = jQuery('select#' + current_event_id + ' option:selected').map(function () { 618 return this.value; 619 }).get(); 620 621 } else if (element_type === 'input' && current_event_type === 'checkbox' && event.attr('multiple') !== undefined) { 622 623 var select_value = jQuery('input#' + current_event_id + ':checked').map(function () { 624 return this.value; 625 }).get(); 626 } else { 627 var select_value = jQuery('#' + current_event_id + extr_attr).val(); 628 } 629 630 return select_value; 631} 632 633jQuery(document).ready(function ($) { 634 // Wait a bit to ensure elements are fully rendered 635 636 setTimeout(function () { 637 638 // Directly target the checkout button and the proceed-to-checkout button 639 $('.wc-block-components-checkout-place-order-button, .wp-block-woocommerce-proceed-to-checkout-block').click(function (event) { 640 641 642 let required_error_is = ''; 643 644let reg_fields_arr = php_array.get_field_detail; 645 646// loop through all visible blocks 647jQuery('.af-urg-checkout-blocks:visible').each(function () { 648 649 let classes = jQuery(this).attr('class'); // full class list 650 651 // extract number only 652 let matched_key = classes.match(/af-urg-checkout-blocks(\d+)/); 653 matched_key = matched_key ? matched_key[1] : null; // only the number, or null if not found 654 655 if (!matched_key) return; // skip if not matched 656 657 reg_fields_arr.forEach(field => { 658 659 if (String(matched_key) === String(field.current_field_id)) { 660 661 let $input = jQuery('#afreg_additionalshowhide_blocks_' + field.current_field_id); 662 663 // text-like fields 664 if (['text', 'email', 'password', 'textarea', 'time', 'date', 'number', 'multiselect'].includes(field.current_field_type)) { 665 666 if (field.afreg_field_required === 'on') { 667 if (!$input.val()) { 668 $input.closest('.wc-block-components-text-input').addClass('has-error'); 669 jQuery('.af_reg_block_error_afreg_additional_' + field.current_field_id).show(); 670 671 required_error_is += get_error_html(); 672 } else { 673 $input.closest('.wc-block-components-text-input').removeClass('has-error'); 674 jQuery('.af_reg_block_error_afreg_additional_' + field.current_field_id).hide(); 675 } 676 } 677 } 678 679 // multi_checkbox / radio 680 if (['multi_checkbox', 'radio'].includes(field.current_field_type)) { 681 682 if (field.afreg_field_required === 'on') { 683 if (!jQuery('.afreg_additional_' + field.current_field_id).is(':checked')) { 684 $input.closest('.wc-block-components-text-input').addClass('has-error'); 685 jQuery('.af_reg_block_error_afreg_additional_' + field.current_field_id).show(); 686 687 required_error_is += get_error_html(); 688 } else { 689 $input.closest('.wc-block-components-text-input').removeClass('has-error'); 690 jQuery('.af_reg_block_error_afreg_additional_' + field.current_field_id).hide(); 691 } 692 } 693 } 694 695 // single checkbox 696 if (field.current_field_type === 'checkbox') { 697 698 if (field.afreg_field_required === 'on') { 699 if (!$input.is(':checked')) { 700 $input.closest('.wc-block-components-text-input').addClass('has-error'); 701 jQuery('.af_reg_block_error_afreg_additional_' + field.current_field_id).first().show(); 702 703 required_error_is += get_error_html(); 704 } else { 705 $input.closest('.wc-block-components-text-input').removeClass('has-error'); 706 jQuery('.af_reg_block_error_afreg_additional_' + field.current_field_id).first().hide(); 707 } 708 } 709 } 710 } 711 }); 712}); 713 714 715 716 if (jQuery('.wc-block-checkout__create-account input[type=checkbox]').is(':checked') && required_error_is) { 717 718 719 720 721 722 723 724 // console.log(reg_fields_arr); 725 726 727 var noticeContainer = jQuery('.woocommerce-notices-wrapper, .woocommerce-message, .wc-block-components-notices'); 728 729 if (!jQuery('.wp-block-woocommerce-cart').length) { 730 731 noticeContainer.first().html(''); 732 733 jQuery('html, body').animate({ 734 scrollTop: jQuery('.af-urf-blocks-main-div ').offset().top 735 }, 'slow'); 736 // jQuery('html, body').animate({ 737 // scrollTop: jQuery('.af-afreg-registration-field').offset().top 738 // }, 500); // 500 is the duration of the scroll in milliseconds 739 740 event.preventDefault(); 741 742 // Optionally, stop event propagation 743 return false;
744 745 } 746 } 747 748 }); 749 750 }, 2000); // Delay the execution by 1 second (adjust as necessary) 751 752 for (let index = 1; index < 5; index++) { 753 754 setTimeout(function () { 755 jQuery('.af-urg-checkout-blocks').each(function () { 756 757 if ($(this).data('current_field_id') && undefined != $(this).data('current_field_id')) { 758 759 let current_field_id = $(this).data('current_field_id'); 760 761 let step__heading = jQuery(this).find('.wc-block-components-checkout-step__heading'); 762 let step__container = jQuery(this).find('.wc-block-components-checkout-step__container'); 763 764 765 // Keep only the first and remove the rest 766 step__heading.not(':first').remove(); 767 step__container.not(':first').remove(); 768 } 769 }); 770 771 }, 1000 * index); 772 773 } 774}); 775 776 777function IsEmail(email) { 778 const regex = 779 /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 780 if (!regex.test(email)) { 781 return false; 782 } 783 else { 784 return true; 785 } 786} 787 788 789jQuery(document).on('change', '#afreg_select_user_role', function () { 790 791 792 // setExtensionData('addify_user_registration_field', 'afreg_select_user_role', jQuery(this).val()); 793 794}); 795
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.