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