1// == Submit Booking Data ============================================================================================== 2 3// Check fields at form and then send request 4function mybooking_submit( submit_form , bk_type, wpdev_active_locale){ 5 6 var target_elm = jQuery( ".booking_form_div" ).trigger( "booking_form_submit_click", [bk_type, submit_form, wpdev_active_locale] ); //FixIn: 8.8.3.13 7 if ( 8 ( jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).length > 0 ) 9 && ( 'pause_submit' === jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).val() ) 10 ) 11 { 12 return false; 13 } 14 15 //FixIn: 8.4.0.2 16 var is_error = wpbc_check_errors_in_booking_form( bk_type ); 17 if ( is_error ) { return false; } 18 19 // Show message if no selected days in Calendar(s) 20 if (document.getElementById('date_booking' + bk_type).value == '') { 21 22 var arr_of_selected_additional_calendars = wpbc_get_arr_of_selected_additional_calendars( bk_type ); //FixIn: 8.5.2.26 23 24 if ( arr_of_selected_additional_calendars.length == 0 ) { 25 wpbc_front_end__show_message__error_under_element( '#booking_form_div' + bk_type + ' .bk_calendar_frame', _wpbc.get_message( 'message_check_no_selected_dates' ), 3000 ); 26 return; 27 } 28 } 29 30 var count = submit_form.elements.length; 31 var formdata = ''; 32 var inp_value; 33 var element; 34 var el_type; 35 36 37 //FixIn:6.1.1.3 38 if( typeof( wpbc_is_this_time_selection_not_available ) == 'function' ) { 39 40 if ( document.getElementById('date_booking' + bk_type).value == '' ) { // Primary calendar not selected. 41 42 if ( document.getElementById('additional_calendars' + bk_type ) != null ) { // Checking additional calendars. 43 44 var id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign 45 var id_additional_arr = id_additional_str.split(','); 46 var is_times_dates_ok = false; 47 for ( var ia=0;ia<id_additional_arr.length;ia++ ) { 48 if ( 49 ( document.getElementById('date_booking' + id_additional_arr[ia] ).value != '' ) 50 && ( ! wpbc_is_this_time_selection_not_available( id_additional_arr[ia], submit_form.elements ) ) 51 ){ 52 is_times_dates_ok = true; 53 } 54 } 55 if ( ! is_times_dates_ok ) return; 56 } 57 } else { //Primary calendar selected. 58 if ( wpbc_is_this_time_selection_not_available( bk_type, submit_form.elements ) ) 59 return; 60 } 61 } 62 63 64 65 // Serialize form here 66 for ( var i = 0; i < count; i++ ){ //FixIn: 9.1.5.1 67 element = submit_form.elements[i]; 68 69 if ( jQuery( element ).closest( '.booking_form_garbage' ).length ) { 70 continue; // Skip elements from garbage //FixIn: 7.1.2.14 71 } 72 73 if ( 74 ( element.type !== 'button' ) 75 && ( element.type !== 'hidden' ) 76 && ( element.name !== ( 'date_booking' + bk_type ) ) 77 // && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element 78 ) { // Skip buttons and hidden element - type //FixIn: 7.2.1.12 79 80 81 // Get Element Value 82 if ( element.type == 'checkbox' ){ 83 84 if (element.value == '') { 85 inp_value = element.checked; 86 } else { 87 if (element.checked) inp_value = element.value; 88 else inp_value = ''; 89 } 90 91 } else if ( element.type == 'radio' ) { 92 93 if (element.checked) { 94 inp_value = element.value; 95 } else { 96 // Check if this radio required, and if it does not check, then show warning, otherwise if it is not required or some other option checked skip this loop 97 // We need to check it here, because radio have the several options with same name and type, and otherwise we will save several options with selected and empty values. 98 if ( //FixIn: 7.0.1.62 99 ( element.className.indexOf('wpdev-validates-as-required') !== -1 ) 100 && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element 101 && ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) ) { 102 wpbc_front_end__show_message__warning( element, _wpbc.get_message( 'message_check_required_for_radio_box' ) ); //FixIn: 8.5.1.3 103 return; 104 } 105 continue; 106 } 107 } else { 108 inp_value = element.value; 109 } 110 111 // Get value in selectbox of multiple selection 112 if ( (element.type == 'selectbox-multiple') || (element.type == 'select-multiple') ){ 113 inp_value = jQuery('[name="'+element.name+'"]').val() ; 114 if (( inp_value == null ) || (inp_value.toString() == '' )) 115 inp_value=''; 116 } 117 118 // Make validation only for visible elements 119 if ( jQuery( element ).is( ':visible' ) ) { //FixIn: 7.2.1.12.2 120 121 122 // Recheck for max num. available visitors selection 123 if ( typeof (wpbc__is_less_than_required__of_max_available_slots__bl) == 'function' ){ 124 if ( wpbc__is_less_than_required__of_max_available_slots__bl( bk_type, element ) ){ 125 return; 126 } 127 } 128 129 130 // Phone validation 131 /*if ( element.name == ('phone'+bk_type) ) { 132 // we validate a phone number of 10 digits with no comma, no spaces, no punctuation and there will be no + sign in front the number - See more at: http://www.w3resource.com/javascript/form/phone-no-vali
132dation.php#sthash.U9FHwcdW.dpuf 133 var reg = /^\d{10}$/; 134 var message_verif_phone = "Please enter correctly phone number"; 135 if ( inp_value != '' ) 136 if(reg.test(inp_value) == false) {wpbc_front_end__show_message__warning( element , message_verif_phone );return;} 137 }*/ 138 139 // Validation Check --- Requred fields 140 if ( element.className.indexOf('wpdev-validates-as-required') !== -1 ){ 141 if ((element.type =='checkbox') && ( element.checked === false)) { 142 if ( ! jQuery(':checkbox[name="'+element.name+'"]', submit_form).is(":checked") ) { 143 wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_required_for_check_box' ) ); //FixIn: 8.5.1.3 144 return; 145 } 146 } 147 if (element.type =='radio') { 148 if ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) { 149 wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_required_for_radio_box' ) ); //FixIn: 8.5.1.3 150 return; 151 } 152 } 153 154 if ( (element.type != 'checkbox') && (element.type != 'radio') && ( '' === wpbc_trim( inp_value ) ) ){ //FixIn: 8.8.1.3 //FixIn:7.0.1.39 //FixIn: 8.7.11.12 155 wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_required' ) ); //FixIn: 8.5.1.3 156 return; 157 } 158 } 159 160 // Validation Check --- Email correct filling field 161 if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ){ 162 inp_value = inp_value.replace(/^\s+|\s+$/gm,''); // Trim white space //FixIn: 5.4.5 163 var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/; 164 if ( inp_value != '' ) 165 if(reg.test(inp_value) == false) { 166 wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_email' ) ); //FixIn: 8.5.1.3 167 return; 168 } 169 } 170 171 // Validation Check --- Same Email Field 172 if ( ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) && ( element.className.indexOf('same_as_') !== -1 ) ) { 173 174 // Get the name of Primary Email field from the "same_as_NAME" class 175 var primary_email_name = element.className.match(/same_as_([^\s])+/gi); 176 if (primary_email_name != null) { // We found 177 primary_email_name = primary_email_name[0].substr(8); 178 179 // Recehck if such primary email field exist in the booking form 180 if (jQuery('[name="' + primary_email_name + bk_type + '"]').length > 0) { 181 182 // Recheck the values of the both emails, if they do not equla show warning 183 if ( jQuery('[name="' + primary_email_name + bk_type + '"]').val() !== inp_value ) { 184 wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_same_email' ) ); //FixIn: 8.5.1.3 185 return; 186 } 187 } 188 } 189 // Skip one loop for the email veryfication field 190 continue; //FixIn: 8.1.2.15 191 } 192 193 } 194 195 // Get Form Data 196 if ( element.name !== ('captcha_input' + bk_type) ) { 197 if (formdata !=='') formdata += '~'; // next field element 198 199 el_type = element.type; 200 if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) el_type='email'; 201 if ( element.className.indexOf('wpdev-validates-as-coupon') !== -1 ) el_type='coupon'; 202 203 inp_value = inp_value + ''; 204 inp_value = inp_value.replace(new RegExp("\\^",'g'), '^'); // replace registered characters 205 inp_value = inp_value.replace(new RegExp("~",'g'), '~'); // replace registered characters 206 207 inp_value = inp_value.replace(/"/g, '"'); // replace double quot 208 inp_value = inp_value.replace(/'/g, '''); // replace single quot 209 210 if ( 'select-one' == el_type ){ 211 el_type = 'selectbox-one' 212 } 213 if ( 'select-multiple' == el_type ){ 214 el_type = 'selectbox-multiple' 215 } 216 217 formdata += el_type + '^' + element.name + '^' + inp_value ; // element attr 218 } 219 } 220 221 } // End Fields Loop 222 223 224 // TODO: here was function for 'Check if visitor finish dates selection. 225 226 227 // Cpatch verify 228 var captcha = document.getElementById('wpdev_captcha_challenge_' + bk_type); 229 230 //Disable Submit button 231 if (captcha != null) form_submit_send( bk_type, formdata, captcha.value, document.getElementById('captcha_input' + bk_type).value ,wpdev_active_locale); 232 else form_submit_send( bk_type, formdata, '', '' , wpdev_active_locale); 233 return; 234} 235 236 237// Gathering params for sending Ajax request and then send it 238function form_submit_send( bk_type, formdata, captcha_chalange, user_captcha ,wpdev_active_locale){ 239 240 var my_booking_form = ''; 241 if ( document.getElementById( 'booking_form_type' + bk_type ) != undefined ){ 242 my_booking_form = document.getElementById( 'booking_form_type' + bk_type ).value; 243 } 244 245 var my_booking_hash = ''; 246 if ( _wpbc.get_other_param( 'this_page_booking_hash' ) != '' ){ 247 my_booking_hash = _wpbc.get_other_param( 'this_page_booking_hash' ); 248 } 249 250 var is_send_emeils = 1; 251 if ( jQuery('#is_send_email_for_pending').length ) { 252 is_send_emeils = jQuery( '#is_send_email_for_pending' ).is( ':checked' ); //FixIn: 8.7.9.5 253 if ( false === is_send_emeils ) { is_send_emeils = 0; } 254 else { is_send_emeils = 1; } 255 } 256 257 if ( document.getElementById( 'date_booking' + bk_type ).value != '' ){ //FixIn:6.1.1.3 258 send_ajax_submit( bk_type, formdata, captcha_chalange, user_captcha, is_send_emeils, my_booking_hash, my_booking_form, wpdev_active_locale ); // Ajax sending request 259 } else { 260 jQuery( '#booking_form_div' + bk_type ).hide(); 261 jQuery( '#submiting' + bk_type ).hide(); 262 } 263 264 var formdata_additional_arr; 265 var formdata_additional; 266 var my_form_field; 267 var id_additional; 268 var id_additional_str; 269 var id_additional_arr; 270 if ( document.getElementById( 'additional_calendars' + bk_type ) != null ){ 271 272 id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign 273 id_additional_arr = id_additional_str.split(','); 274 275 if ( ! jQuery( '#booking_form_div' + bk_type ).is( ':visible' ) ) { 276 wpbc_booking_form__spin_loader__show( bk_type ); // Show Spinner 277 } 278 279 for ( var ia = 0; ia < id_additional_arr.length; ia++ ){ 280 formdata_additional_arr = formdata; 281 formdata_additional = ''; 282 id_additional = id_additional_arr[ia]; 283 284 285 formdata_additional_arr = formdata_additional_arr.split('~'); 286 for (var j=0;j<formdata_additional_arr.length;j++) { 287 my_form_field = formdata_additional_arr[j].split('^'); 288 if (formdata_additional !=='') formdata_additional += '~'; 289 290 if (my_form_field[1].substr( (my_form_field[1].length -2),2)=='[]') 291 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) - 2 ) + id_additional + '[]'; 292 else 293 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) ) + id_additional ; 294 295 296 formdata_additional += my_form_field[0] + '^' + my_form_field[1] + '^' + my_form_field[2]; 297 } 298 299 if ( jQuery('#gateway_payment_forms' + bk_type).length > 0 ) { // If Payment form for main booking resources is showing then append payment form for additional calendars. 300 jQuery('#gateway_payment_forms' + bk_type).after('<div id="gateway_payment_forms'+id_additional+'"></div>'); 301 jQuery('#gateway_payment_forms' + bk_type).after('<div id="ajax_respond_insert'+id_additional+'" style="display:none;"></div>'); 302 } 303 //FixIn: 8.5.2.17 304 send_ajax_submit( id_additional ,formdata_additional,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form ,wpdev_active_locale ); // Submit 305 } 306 } 307} 308 309 310//<![CDATA[ 311function send_ajax_submit( resource_id, formdata, captcha_chalange, user_captcha, is_send_emeils, my_booking_hash, my_booking_form, wpdev_active_locale ){ 312 313 // Disable Submit | Show spin loader 314 wpbc_booking_form__on_submit__ui_elements_disable( resource_id ) 315 316 var is_exit = wpbc_ajx_booking__create( { 317 'resource_id' : resource_id, 318 'dates_ddmmyy_csv' : document.getElementById( 'date_booking' + resource_id ).value, 319 'formdata' : formdata, 320 'booking_hash' : my_booking_hash, 321 'custom_form' : my_booking_form, 322 'aggregate_resource_id_arr': ( ( null !== _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' )) 323 ? _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' ).join( ',' ) : ''), 324 'captcha_chalange' : captcha_chalange, 325 'captcha_user_input' : user_captcha, 326 327 'is_emails_send' : is_send_emeils, 328 'active_locale' : wpdev_active_locale 329 } ); 330 if ( true === is_exit ){ 331 return; 332 } 333} 334//]]> 335 336 337// Hint labels inside of input boxes 338jQuery(document).ready( function(){ 339 340 jQuery('div.inside_hint').on( 'click', function(){ //FixIn: 8.7.11.12 341 jQuery(this).css('visibility', 'hidden').siblings('.has-inside-hint').trigger( 'focus' ); //FixIn: 8.7.11.12 342 }); 343 344 jQuery('input.has-inside-hint').on( 'blur', function(){ //FixIn: 8.7.11.12 345 if ( this.value == '' ) 346 jQuery(this).siblings('.inside_hint').css('visibility', ''); 347 }).on( 'focus', function(){ //FixIn: 8.7.11.12 348 jQuery(this).siblings('.inside_hint').css('visibility', 'hidden'); 349 }); 350 351 jQuery('.booking_form_div input[type=button]').prop("disabled", false); 352}); 353 354// == Support Functions ================================================================================================ 355 356//FixIn: 8.8.1.3 357/** 358 * Trim strings and array joined with (,) 359 * 360 * @param string_to_trim string / array 361 * @returns string 362 */
363function wpbc_trim( string_to_trim ){ 364 365 if ( Array.isArray( string_to_trim ) ){ 366 string_to_trim = string_to_trim.join( ',' ); 367 } 368 369 if ( 'string' == typeof (string_to_trim) ){ 370 string_to_trim = string_to_trim.trim(); 371 } 372 373 return string_to_trim; 374} 375 376function wpdev_in_array (array_here, p_val) { 377 for(var i = 0, l = array_here.length; i < l; i++) { 378 if(array_here[i] == p_val) { 379 return true; 380 } 381 } 382 return false; 383} 384 385//FixIn: 8.4.0.2 386/** 387 * Check errors in booking form fields, and show warnings if some errors exist. 388 * Check errors, like not selected dates or not filled requred form fields, or not correct entering email or phone fields, etc... 389 * 390 * @param bk_type int (ID of booking resource) 391 */ 392function wpbc_check_errors_in_booking_form( bk_type ) { 393 394 var is_error_in_field = false; // By default, all is good - no error 395 396 var my_form = jQuery( '#booking_form' + bk_type ); 397 398 if ( my_form.length ) { 399 400 var fields_with_errors_arr = []; 401 402 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 403 my_form.find( ':input' ).each( function( index, el ) { 404 405 // Skip some elements 406 var skip_elements = [ 'hidden', 'button' ]; 407 408 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 409 410 // Check Calendar Dates Selection 411 if ( ( 'date_booking' + bk_type ) == jQuery( el ).attr( 'name' ) ) { 412 413 // Show Warning only if the calendar visible ( we are at step with calendar) 414 if ( 415 ( ( jQuery( '#calendar_booking' + bk_type ).is( ':visible' ) ) && ( '' == jQuery( el ).val() ) ) 416 && ( wpbc_get_arr_of_selected_additional_calendars( bk_type ).length == 0 ) //FixIn: 8.5.2.26 417 ){ //FixIn: 8.4.4.5 418 419 var notice_message_id = wpbc_front_end__show_message__error_under_element( '#booking_form_div' + bk_type + ' .bk_calendar_frame', _wpbc.get_message( 'message_check_no_selected_dates' ) , 3000 ); 420 421 //wpbc_do_scroll('#calendar_booking' + bk_type); // Scroll to the calendar //FixIn: 8.5.1.3 422 is_error_in_field = true; // Error 423 } 424 } 425 426 // Check only visible elements at this step 427 if ( jQuery( el ).is( ':visible' ) ){ 428// console.log( '|id, type, val, visible|::', jQuery( el ).attr( 'name' ), '|' + jQuery( el ).attr( 'type' ) + '|', jQuery( el ).val(), jQuery( el ).is( ':visible' ) ); 429 430 // Is Required 431 if ( jQuery( el ).hasClass( 'wpdev-validates-as-required' ) ){ 432 433 // Checkboxes 434 if ( 'checkbox' == jQuery( el ).attr( 'type' ) ){ 435 436 if ( 437 ( ! jQuery( el ).is( ':checked' )) 438 && ( ! jQuery( ':checkbox[name="' + el.name + '"]', my_form ).is( ":checked" ) ) //FixIn: 8.5.2.12 439 ){ 440 var checkbox_parent_element; 441 442 if ( jQuery( el ).parents( '.wpdev-form-control-wrap' ).length > 0 ){ 443 444 checkbox_parent_element = jQuery( el ).parents( '.wpdev-form-control-wrap' ); 445 446 } else if ( jQuery( el ).parents( '.controls' ).length > 0 ){ 447 448 checkbox_parent_element = jQuery( el ).parents( '.controls' ); 449 450 } else { 451 452 checkbox_parent_element = jQuery( el ); 453 } 454 var notice_message_id = wpbc_front_end__show_message__warning( checkbox_parent_element, _wpbc.get_message( 'message_check_required_for_check_box' ) ); 455 456 fields_with_errors_arr.push( el ); 457 is_error_in_field = true; // Error 458 } 459 460 // Radio boxes 461 } else if ( 'radio' == jQuery( el ).attr( 'type' ) ){ 462 463 if ( !jQuery( ':radio[name="' + jQuery( el ).attr( 'name' ) + '"]', my_form ).is( ':checked' ) ){ 464 var notice_message_id = wpbc_front_end__show_message__warning( jQuery( el ).parents('.wpdev-form-control-wrap'), _wpbc.get_message( 'message_check_required_for_radio_box' ) ); 465 fields_with_errors_arr.push( el ); 466 is_error_in_field = true; // Error 467 } 468 469 // Other elements 470 } else { 471 472 var inp_value = jQuery( el ).val(); 473 474 if ( '' === wpbc_trim( inp_value ) ){ //FixIn: 8.8.1.3 //FixIn: 8.7.11.12 475 476 var notice_message_id = wpbc_front_end__show_message__warning( el, _wpbc.get_message( 'message_check_required' ) ); 477 478 fields_with_errors_arr.push( el ); 479 is_error_in_field = true; // Error 480 } 481 } 482 } 483 484 // Validate Email 485 if ( jQuery( el ).hasClass( 'wpdev-validates-as-email' ) ){ 486 var inp_value = jQuery( el ).val(); 487 inp_value = inp_value.replace( /^\s+|\s+$/gm, '' ); // Trim white space //FixIn: 5.4.5 488 var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/; 489 if ( (inp_value != '') && (reg.test( inp_value ) == false) ){ 490 491 var notice_message_id = wpbc_front_end__show_message__warning( el, _wpbc.get_message( 'message_check_email' ) ); 492 fields_with_errors_arr.push( el ); 493 is_error_in_field = true; // Error 494 } 495 } 496 497 // Validate For digit entering - for example for - Phone 498 // <p>Digit Field:<br />[text* dig_field class:validate_as_digit] </p> 499 // <p>Phone:<br />[text* phone class:validate_digit_8] </p> 500 501 var classList = jQuery( el ).attr( 'class' ); 502 503 if ( classList ){ 504 505 classList = classList.split( /\s+/ ); 506 507 jQuery.each( classList, function ( cl_index, cl_item ){ 508
509 //////////////////////////////////////////////////////////////////////////////////////////// 510 511 // Validate field value as "Date" [CSS class - 'validate_as_digit'] 512 if ( 'validate_as_date' === cl_item ) { 513 514 // Valid values: 09-25-2018, 09/25/2018, 09-25-2018, 31-9-1918 --- m/d/Y, m.d.Y, m-d-Y, d/m/Y, d.m.Y, d-m-Y 515 var regex = new RegExp( '^[0-3]?\\d{1}[\\/\\.\\-]+[0-3]?\\d{1}[\\/\\.\\-]+[0-2]+\\d{3}$' ); // Check for Date 09/25/2018 516 var message_verif_phone = 'This field must be valid date like this ' + '09/25/2018'; 517 var inp_value = jQuery( el ).val(); 518 519 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 520 wpbc_front_end__show_message__warning( el, message_verif_phone ); 521 fields_with_errors_arr.push( el ); 522 is_error_in_field = true; // Error 523 } 524 } 525
526 //////////////////////////////////////////////////////////////////////////////////////////// 527 528 // Validate field value as "DIGIT" [CSS class - 'validate_as_digit'] 529 if ( 'validate_as_digit' === cl_item ) { 530 531 var regex = new RegExp( '^[0-9]+\\.?[0-9]*$' ); // Check for digits 532 var message_verif_phone = 'This field must contain only digits'; 533 var inp_value = jQuery( el ).val(); 534 535 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 536 wpbc_front_end__show_message__warning( el, message_verif_phone ); 537 fields_with_errors_arr.push( el ); 538 is_error_in_field = true; // Error 539 } 540 } 541 542 //////////////////////////////////////////////////////////////////////////////////////////// 543 544 // Validate field value as "Phone" number or any other valid number wth specific number of digits [CSS class - 'validate_digit_8' || 'validate_digit_10' ] 545 var is_validate_digit = cl_item.substring( 0, 15 ); 546 547 // Check if class start with 'validate_digit_' 548 if ( 'validate_digit_' === is_validate_digit ){ 549 550 // Get number of digit in class: validate_digit_8 => 8 or validate_digit_10 => 10 551 var digits_to_check = parseInt( cl_item.substring( 15 ) ); 552 553 // Check about any errors in 554 if ( !isNaN( digits_to_check ) ){ 555 556 var regex = new RegExp( '^\\d{' + digits_to_check + '}$' ); // We was valid it as parseInt - only integer variable - digits_to_check 557 var message_verif_phone = 'This field must contain ' + digits_to_check + ' digits'; 558 var inp_value = jQuery( el ).val(); 559 560 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 561 wpbc_front_end__show_message__warning( el, message_verif_phone ); 562 fields_with_errors_arr.push( el ); 563 is_error_in_field = true; // Error 564 } 565 } 566 } 567
568 //////////////////////////////////////////////////////////////////////////////////////////// 569 570 }); 571 } 572 } 573 } 574 } ); 575 576 if ( fields_with_errors_arr.length > 0 ){ 577 jQuery( fields_with_errors_arr[ 0 ] ).trigger( 'focus' ); //FixIn: 9.3.1.9 578 } 579 } 580 581 return is_error_in_field; 582} 583 584//FixIn: 8.4.4.4 585function bk_calendar_step_click( el ){ 586 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 587 var is_error = wpbc_check_errors_in_booking_form( br_id ); 588 if ( is_error ){ 589 return false; 590 } 591 if ( br_id != undefined ){ 592 jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "none"} ); 593 jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "block"} ); 594 } else { 595 jQuery( ".bk_calendar_step" ).css( {"display": "none"} ); 596 jQuery( ".bk_form_step" ).css( {"display": "block"} ); 597 } 598} 599 600function bk_form_step_click( el ){ 601 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 602 var is_error = false; // wpbc_check_errors_in_booking_form( br_id ); //FixIn: 8.4.5.6 603 if ( is_error ){ 604 return false; 605 } 606 if ( br_id != undefined ){ 607 jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "block"} ); 608 jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "none"} ); 609 wpbc_do_scroll( "#bklnk" + br_id ); 610 } else { 611 jQuery( ".bk_calendar_step" ).css( {"display": "block"} ); 612 jQuery( ".bk_form_step" ).css( {"display": "none"} ); 613 } 614} 615 616//FixIn: 8.6.1.15 617/** 618 * Go to next specific step in Wizard style booking form, with 619 * check all required elements specific step, otherwise show warning message! 620 * 621 * @param el 622 * @param step_num 623 * @returns {boolean} 624 */ 625function wpbc_wizard_step( el, step_num, step_from ){ 626 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 627 628 //FixIn: 8.8.1.5 629 if ( ( undefined == step_from ) || ( step_num > step_from ) ){ 630 if ( 1 != step_num ){ //FixIn: 8.7.7.8 631 var is_error = wpbc_check_errors_in_booking_form( br_id ); 632 if ( is_error ){ 633 return false; 634 } 635 } 636 } 637 638 if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ 639 if ( wpbc_is_this_time_selection_not_available( br_id, document.getElementById( 'booking_form' + br_id ) ) ){ 640 return false; 641 } 642 } 643 644 if ( br_id != undefined ){ 645 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" ).css( {"display": "none"} ).removeClass('wpbc_wizard_step_hidden'); 646 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" + step_num ).css( {"display": "block"} ); 647 } 648} 649 650//FixIn: 10.1.3.2 651jQuery( document ).ready( function (){ 652 653 // CSS classes in Wizard Next / Prior links can be like this: <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_1">Step 1</a> | <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_2">Step 2</a> 654 655 jQuery( '.wpbc_wizard_step_button' ).attr( { 656 href: 'javascript:void(0)' 657 } ); 658 659 jQuery( '.wpbc_wizard_step_button' ).on( 'click', function ( event ){ 660 661 var found_steps_arr = jQuery( this ).attr( 'class' ).match( /wpbc\_wizard\_step\_([\d]+)([\s'"]+|$)/ ); 662 663 if ( (null !== found_steps_arr) && (found_steps_arr.length > 2) ){ 664 var step = parseInt( found_steps_arr[ 1 ] ); 665 if ( step > 0 ){ 666 wpbc_wizard_step( this, step ); 667 } 668 } 669 } ); 670 671} ); 672 673 674//FixIn: 8.6.1.15 675/** 676 * Check if at least one element from array of elements names in booking form visible or not. 677 * Usage Example: if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ ... } 678 * 679 * @param bk_type 680 * @param elements_names 681 * @returns {boolean} 682 */
683function wpbc_is_some_elements_visible( bk_type, elements_names ){ 684 685 var is_some_elements_visible = false; 686 687 var my_form = jQuery( '#booking_form' + bk_type ); 688 689 if ( my_form.length ){ 690 691 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 692 my_form.find( ':input' ).each( function ( index, el ){ 693 694 // Skip some elements 695 var skip_elements = ['hidden', 'button']; 696 697 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 698 699 for ( var ei = 0; ei < ( elements_names.length - 1) ; ei++ ){ 700 701 // Check Calendar Dates Selection 702 if ( (elements_names[ ei ] + bk_type) == jQuery( el ).attr( 'name' ) ){ 703 704 if ( jQuery( el ).is( ':visible' ) ){ 705 is_some_elements_visible = true; 706 } 707 } 708 } 709 } 710 } ); 711 } 712 return is_some_elements_visible; 713} 714 715// == Days Selections - support functions ============================================================================== 716 717/** 718 * Get first day of selection 719 * 720 * @param dates 721 * @returns {string|*} 722 */ 723function get_first_day_of_selection(dates) { 724 725 // Multiple days selections 726 if ( dates.indexOf( ',' ) != -1 ){ 727 var dates_array = dates.split( /,\s*/ ); 728 var length = dates_array.length; 729 var element = null; 730 var new_dates_array = []; 731 732 for ( var i = 0; i < length; i++ ){ 733 734 element = dates_array[ i ].split( /\./ ); 735 736 new_dates_array[ new_dates_array.length ] = element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //2013.12.20 737 } 738 new_dates_array.sort(); 739 740 element = new_dates_array[ 0 ].split( /\./ ); 741 742 return element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //20.12.2013 743 } 744 745 // Range days selection 746 if ( dates.indexOf( ' - ' ) != -1 ){ 747 var start_end_date = dates.split( " - " ); 748 return start_end_date[ 0 ]; 749 } 750 751 // Single day selection 752 return dates; //20.12.2013 753} 754 755// Get last day of selection 756function get_last_day_of_selection(dates) { 757 758 // Multiple days selections 759 if ( dates.indexOf(',') != -1 ){ 760 var dates_array =dates.split(/,\s*/); 761 var length = dates_array.length; 762 var element = null; 763 var new_dates_array = []; 764 765 for (var i = 0; i < length; i++) { 766 767 element = dates_array[i].split(/\./); 768 769 new_dates_array[new_dates_array.length] = element[2]+'.' + element[1]+'.' + element[0]; //2013.12.20 770 } 771 new_dates_array.sort(); 772 773 element = new_dates_array[(new_dates_array.length-1)].split(/\./); 774 775 return element[2]+'.' + element[1]+'.' + element[0]; //20.12.2013 776 } 777 778 // Range days selection 779 if ( dates.indexOf(' - ') != -1 ){ 780 var start_end_date = dates.split(" - "); 781 return start_end_date[(start_end_date.length-1)]; 782 } 783 784 // Single day selection 785 return dates; //20.12.2013 786} 787 788 789/** 790 * Check ID of selected additional calendars 791 * 792 * @param int bk_type 793 * @returns array 794 */ 795function wpbc_get_arr_of_selected_additional_calendars( bk_type ){ //FixIn: 8.5.2.26 796 797 var selected_additionl_calendars = []; 798 799 // Checking according additional calendars 800 if ( document.getElementById( 'additional_calendars' + bk_type ) != null ){ 801 802 var id_additional_str = document.getElementById( 'additional_calendars' + bk_type ).value; 803 var id_additional_arr = id_additional_str.split( ',' ); 804 805 var is_all_additional_days_unselected = true; 806 807 for ( var ia = 0; ia < id_additional_arr.length; ia++ ){ 808 if ( document.getElementById( 'date_booking' + id_additional_arr[ ia ] ).value != '' ){ 809 selected_additionl_calendars.push( id_additional_arr[ ia ] ); 810 } 811 } 812 } 813 return selected_additionl_calendars; 814}
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.