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 //FixIn: 10.9.4.1. 275 for ( var ia = 0; ia < id_additional_arr.length; ia++ ) { 276 id_additional_arr[ia] = parseInt( id_additional_arr[ia] ); 277 } 278 if ( ! jQuery( '#booking_form_div' + bk_type ).is( ':visible' ) ) { 279 wpbc_booking_form__spin_loader__show( bk_type ); // Show Spinner 280 } 281 282 for ( var ia = 0; ia < id_additional_arr.length; ia++ ){ 283 //FixIn: 10.9.4.1. 284 if ( id_additional_arr[ia] <=0 ) { 285 continue; 286 } 287 288 289 formdata_additional_arr = formdata; 290 formdata_additional = ''; 291 id_additional = id_additional_arr[ia]; 292 293 294 formdata_additional_arr = formdata_additional_arr.split('~'); 295 for (var j=0;j<formdata_additional_arr.length;j++) { 296 my_form_field = formdata_additional_arr[j].split('^'); 297 if (formdata_additional !=='') formdata_additional += '~'; 298 299 if (my_form_field[1].substr( (my_form_field[1].length -2),2)=='[]') 300 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) - 2 ) + id_additional + '[]'; 301 else 302 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) ) + id_additional ; 303 304 305 formdata_additional += my_form_field[0] + '^' + my_form_field[1] + '^' + my_form_field[2]; 306 } 307 308 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. 309 jQuery('#gateway_payment_forms' + bk_type).after('<div id="gateway_payment_forms'+id_additional+'"></div>'); 310 jQuery('#gateway_payment_forms' + bk_type).after('<div id="ajax_respond_insert'+id_additional+'" style="display:none;"></div>'); 311 } 312 // FixIn: 8.5.2.17. 313 send_ajax_submit( id_additional ,formdata_additional,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form ,wpdev_active_locale ); // Submit 314 } 315 } 316} 317 318 319//<![CDATA[ 320function send_ajax_submit( resource_id, formdata, captcha_chalange, user_captcha, is_send_emeils, my_booking_hash, my_booking_form, wpdev_active_locale ){ 321 322 // Disable Submit | Show spin loader 323 wpbc_booking_form__on_submit__ui_elements_disable( resource_id ) 324 325 var is_exit = wpbc_ajx_booking__create( { 326 'resource_id' : resource_id, 327 'dates_ddmmyy_csv' : document.getElementById( 'date_booking' + resource_id ).value, 328 'formdata' : formdata, 329 'booking_hash' : my_booking_hash, 330 'custom_form' : my_booking_form, 331 'aggregate_resource_id_arr': ( ( null !== _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' )) 332 ? _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' ).join( ',' ) : ''), 333 'captcha_chalange' : captcha_chalange, 334 'captcha_user_input' : user_captcha, 335 336 'is_emails_send' : is_send_emeils, 337 'active_locale' : wpdev_active_locale 338 } ); 339 if ( true === is_exit ){ 340 return; 341 } 342} 343//]]> 344 345 346// Hint labels inside of input boxes 347jQuery(document).ready( function(){ 348 349 jQuery('div.inside_hint').on( 'click', function(){ // FixIn: 8.7.11.12. 350 jQuery(this).css('visibility', 'hidden').siblings('.has-inside-hint').trigger( 'focus' ); // FixIn: 8.7.11.12. 351 }); 352 353 jQuery('input.has-inside-hint').on( 'blur', function(){ // FixIn: 8.7.11.12. 354 if ( this.value == '' ) 355 jQuery(this).siblings('.inside_hint').css('visibility', ''); 356 }).on( 'focus', function(){ // FixIn: 8.7.11.12. 357 jQuery(this).siblings('.inside_hint').css('visibility', 'hidden'); 358 }); 359 360 jQuery('.booking_form_div input[type=button]').prop("disabled", false); 361}); 362 363 364// FixIn: 8.4.0.2. 365/** 366 * Check errors in booking form fields, and show warnings if some errors exist. 367 * Check errors, like not selected dates or not filled requred form fields, or not correct entering email or phone fields, etc... 368 * 369 * @param bk_type int (ID of booking resource) 370 */
371function wpbc_check_errors_in_booking_form( bk_type ) { 372 373 var is_error_in_field = false; // By default, all is good - no error 374 375 var my_form = jQuery( '#booking_form' + bk_type ); 376 377 if ( my_form.length ) { 378 379 var fields_with_errors_arr = []; 380 381 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 382 my_form.find( ':input' ).each( function( index, el ) { 383 384 // Skip some elements 385 var skip_elements = [ 'hidden', 'button' ]; 386 387 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 388 389 // Check Calendar Dates Selection 390 if ( ( 'date_booking' + bk_type ) == jQuery( el ).attr( 'name' ) ) { 391 392 // Show Warning only if the calendar visible ( we are at step with calendar) 393 if ( 394 ( ( jQuery( '#calendar_booking' + bk_type ).is( ':visible' ) ) && ( '' == jQuery( el ).val() ) ) 395 && ( wpbc_get_arr_of_selected_additional_calendars( bk_type ).length == 0 ) // FixIn: 8.5.2.26. 396 ){ // FixIn: 8.4.4.5. 397 398 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 ); 399 400 //wpbc_do_scroll('#calendar_booking' + bk_type); // Scroll to the calendar // FixIn: 8.5.1.3. 401 is_error_in_field = true; // Error 402 } 403 } 404 405 // Check only visible elements at this step 406 if ( jQuery( el ).is( ':visible' ) ){ 407// console.log( '|id, type, val, visible|::', jQuery( el ).attr( 'name' ), '|' + jQuery( el ).attr( 'type' ) + '|', jQuery( el ).val(), jQuery( el ).is( ':visible' ) ); 408 409 // Is Required 410 if ( jQuery( el ).hasClass( 'wpdev-validates-as-required' ) ){ 411 412 // Checkboxes 413 if ( 'checkbox' == jQuery( el ).attr( 'type' ) ){ 414 415 if ( 416 ( ! jQuery( el ).is( ':checked' )) 417 && ( ! jQuery( ':checkbox[name="' + el.name + '"]', my_form ).is( ":checked" ) ) // FixIn: 8.5.2.12. 418 ){ 419 var checkbox_parent_element; 420 421 if ( jQuery( el ).parents( '.wpdev-form-control-wrap' ).length > 0 ){ 422 423 checkbox_parent_element = jQuery( el ).parents( '.wpdev-form-control-wrap' ); 424 425 } else if ( jQuery( el ).parents( '.controls' ).length > 0 ){ 426 427 checkbox_parent_element = jQuery( el ).parents( '.controls' ); 428 429 } else { 430 431 checkbox_parent_element = jQuery( el ); 432 } 433 var notice_message_id = wpbc_front_end__show_message__warning( checkbox_parent_element, _wpbc.get_message( 'message_check_required_for_check_box' ) ); 434 435 fields_with_errors_arr.push( el ); 436 is_error_in_field = true; // Error 437 } 438 439 // Radio boxes 440 } else if ( 'radio' == jQuery( el ).attr( 'type' ) ){ 441 442 if ( !jQuery( ':radio[name="' + jQuery( el ).attr( 'name' ) + '"]', my_form ).is( ':checked' ) ){ 443 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' ) ); 444 fields_with_errors_arr.push( el ); 445 is_error_in_field = true; // Error 446 } 447 448 // Other elements 449 } else { 450 451 var inp_value = jQuery( el ).val(); 452 453 if ( '' === wpbc_trim( inp_value ) ){ //FixIn: 8.8.1.3 // FixIn: 8.7.11.12. 454 455 var notice_message_id = wpbc_front_end__show_message__warning( el, _wpbc.get_message( 'message_check_required' ) ); 456 457 fields_with_errors_arr.push( el ); 458 is_error_in_field = true; // Error 459 } 460 } 461 } 462 463 // Validate Email 464 if ( jQuery( el ).hasClass( 'wpdev-validates-as-email' ) ){ 465 var inp_value = jQuery( el ).val(); 466 inp_value = inp_value.replace( /^\s+|\s+$/gm, '' ); // Trim white space //FixIn: 5.4.5 467 var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/; 468 if ( (inp_value != '') && (reg.test( inp_value ) == false) ){ 469 470 var notice_message_id = wpbc_front_end__show_message__warning( el, _wpbc.get_message( 'message_check_email' ) ); 471 fields_with_errors_arr.push( el ); 472 is_error_in_field = true; // Error 473 } 474 } 475 476 // Validate For digit entering - for example for - Phone 477 // <p>Digit Field:<br />[text* dig_field class:validate_as_digit] </p> 478 // <p>Phone:<br />[text* phone class:validate_digit_8] </p> 479 480 var classList = jQuery( el ).attr( 'class' ); 481 482 if ( classList ){ 483 484 classList = classList.split( /\s+/ ); 485 486 jQuery.each( classList, function ( cl_index, cl_item ){ 487
488 //////////////////////////////////////////////////////////////////////////////////////////// 489 490 // Validate field value as "Date" [CSS class - 'validate_as_digit'] 491 if ( 'validate_as_date' === cl_item ) { 492 493 // 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 494 var regex = new RegExp( '^[0-3]?\\d{1}[\\/\\.\\-]+[0-3]?\\d{1}[\\/\\.\\-]+[0-2]+\\d{3}$' ); // Check for Date 09/25/2018 495 var message_verif_phone = 'This field must be valid date like this ' + '09/25/2018'; 496 var inp_value = jQuery( el ).val(); 497 498 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 499 wpbc_front_end__show_message__warning( el, message_verif_phone ); 500 fields_with_errors_arr.push( el ); 501 is_error_in_field = true; // Error 502 } 503 } 504
505 //////////////////////////////////////////////////////////////////////////////////////////// 506 507 // Validate field value as "DIGIT" [CSS class - 'validate_as_digit'] 508 if ( 'validate_as_digit' === cl_item ) { 509 510 var regex = new RegExp( '^[0-9]+\\.?[0-9]*$' ); // Check for digits 511 var message_verif_phone = 'This field must contain only digits'; 512 var inp_value = jQuery( el ).val(); 513 514 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 515 wpbc_front_end__show_message__warning( el, message_verif_phone ); 516 fields_with_errors_arr.push( el ); 517 is_error_in_field = true; // Error 518 } 519 } 520 521 //////////////////////////////////////////////////////////////////////////////////////////// 522 523 // Validate field value as "Phone" number or any other valid number wth specific number of digits [CSS class - 'validate_digit_8' || 'validate_digit_10' ] 524 var is_validate_digit = cl_item.substring( 0, 15 ); 525 526 // Check if class start with 'validate_digit_' 527 if ( 'validate_digit_' === is_validate_digit ){ 528 529 // Get number of digit in class: validate_digit_8 => 8 or validate_digit_10 => 10 530 var digits_to_check = parseInt( cl_item.substring( 15 ) ); 531 532 // Check about any errors in 533 if ( !isNaN( digits_to_check ) ){ 534 535 var regex = new RegExp( '^\\d{' + digits_to_check + '}$' ); // We was valid it as parseInt - only integer variable - digits_to_check 536 var message_verif_phone = 'This field must contain ' + digits_to_check + ' digits'; 537 var inp_value = jQuery( el ).val(); 538 539 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 540 wpbc_front_end__show_message__warning( el, message_verif_phone ); 541 fields_with_errors_arr.push( el ); 542 is_error_in_field = true; // Error 543 } 544 } 545 } 546
547 //////////////////////////////////////////////////////////////////////////////////////////// 548 549 }); 550 } 551 } 552 } 553 } ); 554 555 if ( fields_with_errors_arr.length > 0 ){ 556 jQuery( fields_with_errors_arr[ 0 ] ).trigger( 'focus' ); // FixIn: 9.3.1.9. 557 } 558 } 559 560 return is_error_in_field; 561} 562 563 564// FixIn: 8.6.1.15. 565/** 566 * Go to next specific step in Wizard style booking form, with 567 * check all required elements specific step, otherwise show warning message! 568 * 569 * @param el 570 * @param step_num 571 * @returns {boolean} 572 */ 573function wpbc_wizard_step( el, step_num, step_from ){ 574 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 575 576 // FixIn: 8.8.1.5. 577 if ( ( undefined == step_from ) || ( step_num > step_from ) ){ 578 if ( 1 != step_num ){ // FixIn: 8.7.7.8. 579 var is_error = wpbc_check_errors_in_booking_form( br_id ); 580 if ( is_error ){ 581 return false; 582 } 583 } 584 } 585 586 if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ 587 if ( wpbc_is_this_time_selection_not_available( br_id, document.getElementById( 'booking_form' + br_id ) ) ){ 588 return false; 589 } 590 } 591 592 if ( br_id != undefined ){ 593 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" ).css( {"display": "none"} ).removeClass('wpbc_wizard_step_hidden'); 594 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" + step_num ).css( {"display": "block"} ); 595 } 596} 597 598 599/** 600 * Init Buttons in Booking form Wizard 601 */ 602function wpbc_hook__init_booking_form_wizard_buttons() { 603 604 // 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> 605 606 jQuery( '.wpbc_wizard_step_button' ).attr( { 607 href: 'javascript:void(0)' 608 } ); 609 610 jQuery( '.wpbc_wizard_step_button' ).on( 'click', function ( event ){ 611 612 var found_steps_arr = jQuery( this ).attr( 'class' ).match( /wpbc\_wizard\_step\_([\d]+)([\s'"]+|$)/ ); 613 614 if ( (null !== found_steps_arr) && (found_steps_arr.length > 2) ){ 615 var step = parseInt( found_steps_arr[ 1 ] ); 616 if ( step > 0 ){ 617 wpbc_wizard_step( this, step ); 618 } 619 } 620 } ); 621} 622 623// FixIn: 10.1.3.2. 624jQuery( document ).ready( function (){ 625 wpbc_hook__init_booking_form_wizard_buttons(); 626} ); 627 628 629// FixIn: 8.6.1.15. 630/** 631 * Check if at least one element from array of elements names in booking form visible or not. 632 * Usage Example: if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ ... } 633 * 634 * @param bk_type 635 * @param elements_names 636 * @returns {boolean} 637 */ 638function wpbc_is_some_elements_visible( bk_type, elements_names ){ 639 640 var is_some_elements_visible = false; 641 642 var my_form = jQuery( '#booking_form' + bk_type ); 643 644 if ( my_form.length ){ 645 646 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 647 my_form.find( ':input' ).each( function ( index, el ){ 648 649 // Skip some elements 650 var skip_elements = ['hidden', 'button']; 651 652 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 653 654 for ( var ei = 0; ei < ( elements_names.length - 1) ; ei++ ){ 655 656 // Check Calendar Dates Selection 657 if ( (elements_names[ ei ] + bk_type) == jQuery( el ).attr( 'name' ) ){ 658 659 if ( jQuery( el ).is( ':visible' ) ){ 660 is_some_elements_visible = true; 661 } 662 } 663 } 664 } 665 } ); 666 } 667 return is_some_elements_visible; 668} 669 670// == Days Selections - support functions ============================================================================== 671 672/** 673 * Get first day of selection 674 * 675 * @param dates 676 * @returns {string|*} 677 */ 678function get_first_day_of_selection(dates) { 679 680 // Multiple days selections 681 if ( dates.indexOf( ',' ) != -1 ){ 682 var dates_array = dates.split( /,\s*/ ); 683 var length = dates_array.length; 684 var element = null; 685 var new_dates_array = []; 686 687 for ( var i = 0; i < length; i++ ){ 688 689 element = dates_array[ i ].split( /\./ ); 690 691 new_dates_array[ new_dates_array.length ] = element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //2013.12.20 692 } 693 new_dates_array.sort(); 694 695 element = new_dates_array[ 0 ].split( /\./ ); 696 697 return element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //20.12.2013 698 } 699 700 // Range days selection 701 if ( dates.indexOf( ' - ' ) != -1 ){ 702 var start_end_date = dates.split( " - " ); 703 return start_end_date[ 0 ]; 704 } 705 706 // Single day selection 707 return dates; //20.12.2013 708} 709 710// Get last day of selection 711function get_last_day_of_selection(dates) { 712 713 // Multiple days selections 714 if ( dates.indexOf(',') != -1 ){ 715 var dates_array =dates.split(/,\s*/); 716 var length = dates_array.length; 717 var element = null; 718 var new_dates_array = []; 719 720 for (var i = 0; i < length; i++) { 721 722 element = dates_array[i].split(/\./); 723 724 new_dates_array[new_dates_array.length] = element[2]+'.' + element[1]+'.' + element[0]; //2013.12.20 725 } 726 new_dates_array.sort(); 727 728 element = new_dates_array[(new_dates_array.length-1)].split(/\./); 729 730 return element[2]+'.' + element[1]+'.' + element[0]; //20.12.2013 731 } 732 733 // Range days selection 734 if ( dates.indexOf(' - ') != -1 ){ 735 var start_end_date = dates.split(" - "); 736 return start_end_date[(start_end_date.length-1)]; 737 } 738 739 // Single day selection 740 return dates; //20.12.2013 741} 742 743 744/** 745 * Check ID of selected additional calendars 746 * 747 * @param int bk_type 748 * @returns array 749 */
750function wpbc_get_arr_of_selected_additional_calendars( bk_type ){ // FixIn: 8.5.2.26. 751 752 var selected_additionl_calendars = []; 753 754 // Checking according additional calendars 755 if ( document.getElementById( 'additional_calendars' + bk_type ) != null ){ 756 757 var id_additional_str = document.getElementById( 'additional_calendars' + bk_type ).value; 758 var id_additional_arr = id_additional_str.split( ',' ); 759 760 var is_all_additional_days_unselected = true; 761 762 for ( var ia = 0; ia < id_additional_arr.length; ia++ ){ 763 if ( document.getElementById( 'date_booking' + id_additional_arr[ ia ] ).value != '' ){ 764 selected_additionl_calendars.push( id_additional_arr[ ia ] ); 765 } 766 } 767 } 768 return selected_additionl_calendars; 769}
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.