1 2var __gf_timeout_handle; 3 4gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) { 5 if( ! window.gf_form_conditional_logic ) { 6 return; 7 } 8 var dependentFieldIds = rgars( gf_form_conditional_logic, [ formId, 'fields', gformExtractFieldId( fieldId ) ].join( '/' ) ); 9 if( dependentFieldIds ) { 10 gf_apply_rules( formId, dependentFieldIds ); 11 } 12}, 10 ); 13 14function gf_apply_rules(formId, fields, isInit){ 15 16 jQuery(document).trigger( 'gform_pre_conditional_logic', [ formId, fields, isInit ] ); 17 gform.utils.trigger( { 18 event: 'gform/conditionalLogic/applyRules/start', 19 native: false, 20 data: { formId: formId, fields: fields, isInit: isInit }, 21 } ); 22 for(var i=0; i < fields.length; i++){ 23 gf_apply_field_rule(formId, fields[i], isInit, function(){ 24 var is_last_field = ( i >= fields.length - 1 ); 25 if( is_last_field ) { 26 27 // Gather the fields that are dependents of the processed fields (inside pages/sections). 28 var dependentFields = []; 29 var dependents = window["gf_form_conditional_logic"][formId]["dependents"][fields[i]]; 30 if ( dependents ) { 31 dependents.forEach( function ( dependentFieldId ) { 32 if ( dependentFields.indexOf( dependentFieldId ) === -1 ) { 33 dependentFields.push( dependentFieldId ); 34 } 35 }); 36 } 37 38 jQuery(document).trigger('gform_post_conditional_logic', [formId, fields, isInit]); 39 gform.utils.trigger( { 40 event: 'gform/conditionalLogic/applyRules/end', 41 native: false, 42 data: { formId: formId, fields: fields, dependentFields: dependentFields, isInit: isInit }, 43 } ); 44 if( window.gformCalculateTotalPrice ) { 45 window.gformCalculateTotalPrice( formId ); 46 } 47 } 48 }); 49 } 50} 51 52function gf_check_field_rule(formId, fieldId, isInit, callback){ 53 54 //if conditional logic is not specified for that field, it is supposed to be displayed 55 var conditionalLogic = gf_get_field_logic( formId, fieldId ); 56 if ( ! conditionalLogic ) { 57 return 'show'; 58 } 59 60 var action = gf_get_field_action(formId, conditionalLogic["section"]); 61 62 //If section is hidden, always hide field. If section is displayed, see if field is supposed to be displayed or hidden 63 if(action != "hide") 64 action = gf_get_field_action(formId, conditionalLogic["field"]); 65 66 return action; 67} 68 69/** 70 * Retrieves the conditional logic properties for the specified field. 71 * 72 * @since 2.4.16 73 * 74 * @param {(string|number)} formId The ID of the current form. 75 * @param {(string|number)} fieldId The ID of the current field. 76 * 77 * @return {(boolean|object)} False or the field conditional logic properties. 78 */ 79function gf_get_field_logic(formId, fieldId) { 80 var formConditionalLogic = rgars( window, 'gf_form_conditional_logic/' + formId ); 81 if ( ! formConditionalLogic ) { 82 return false; 83 } 84 85 var conditionalLogic = rgars( formConditionalLogic, 'logic/' + fieldId ); 86 if ( conditionalLogic ) { 87 return conditionalLogic; 88 } 89 90 var dependents = rgar( formConditionalLogic, 'dependents' ); 91 if ( ! dependents ) { 92 return false; 93 } 94 95 // Attempting to get section field conditional logic instead. 96 for ( var key in dependents ) { 97 if ( dependents[key].indexOf( fieldId ) !== -1 ) { 98 return rgars( formConditionalLogic, 'logic/' + key ); 99 } 100 } 101 102 return false; 103} 104 105function gf_apply_field_rule(formId, fieldId, isInit, callback){ 106 107 var action = gf_check_field_rule(formId, fieldId, isInit, callback); 108 109 gf_do_field_action(formId, action, fieldId, isInit, callback); 110 111 var conditionalLogic = window["gf_form_conditional_logic"][formId]["logic"][fieldId]; 112 //perform conditional logic for the next button 113 if(conditionalLogic["nextButton"]){ 114 action = gf_get_field_action(formId, conditionalLogic["nextButton"]); 115 gf_do_next_button_action(formId, action, fieldId, isInit); 116 } 117 118} 119 120function gf_get_field_action(formId, conditionalLogic){ 121 if(!conditionalLogic) 122 return "show"; 123 124 var matches = 0; 125 for(var i = 0; i < conditionalLogic["rules"].length; i++){ 126 /** 127 * Filter the conditional logic rule before it is evaluated on the frontend. 128 * 129 * @param {object} rule The conditional logic rule about to be evaluated. 130 * @param {(string|number)} formId The current form ID. 131 * @param {object} conditionalLogic All details required to evaluate an objects conditional logic. 132 * 133 * @since 2.4.22 134 */ 135 var rule = gform.applyFilters( 'gform_rule_pre_evaluation', jQuery.extend( {}, conditionalLogic["rules"][i] ), formId, conditionalLogic ); 136 if(gf_is_match(formId, rule)) 137 matches++; 138 } 139 140 var action; 141 if( (conditionalLogic["logicType"] == "all" && matches == conditionalLogic["rules"].length) || (conditionalLogic["logicType"] == "any" && matches > 0) ) 142 action = conditionalLogic["actionType"]; 143 else
144 action = conditionalLogic["actionType"] == "show" ? "hide" : "show"; 145 146 return action; 147} 148 149function gf_is_match( formId, rule ) { 150 151 var $ = jQuery, 152 inputId = rule['fieldId'], 153 fieldId = gformExtractFieldId( inputId ), 154 inputIndex = gformExtractInputIndex( inputId ), 155 isInputSpecific = inputIndex !== false, 156 $inputs; 157 158 if( isInputSpecific ) { 159 $inputs = $( '#input_{0}_{1}_{2}, #choice_{0}_{1}_{2}'.gformFormat( formId, fieldId, inputIndex ) ); 160 } else { 161 $inputs = $( 'input[id="input_{0}_{1}"], input[id^="input_{0}_{1}_"], input[id^="choice_{0}_{1}_"], select#input_{0}_{1}, textarea#input_{0}_{1}'.gformFormat( formId, fieldId ) ); 162 } 163 164 var isCheckable = $.inArray( $inputs.attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1; 165 var isMatch = isCheckable ? gf_is_match_checkable( $inputs, rule, formId, fieldId ) : gf_is_match_default( $inputs.eq( 0 ), rule, formId, fieldId ); 166 167 return gform.applyFilters( 'gform_is_value_match', isMatch, formId, rule ); 168} 169 170function gf_is_match_checkable( $inputs, rule, formId, fieldId ) { 171 172 // Rule is checking if the checkable is/isn't blank. Return a specific check for that use-case. 173 if ( rule.value === '' ) { 174 return rule.operator === 'is' ? gf_is_checkable_empty( $inputs ) : ! gf_is_checkable_empty( $inputs ); 175 } 176 177 var isMatch = false; 178 179 $inputs.each( function() { 180 181 var $input = jQuery( this ), 182 fieldValue = gf_get_value( $input.val(), $input ), 183 isRangeOperator = jQuery.inArray( rule.operator, [ '<', '>' ] ) !== -1, 184 isStringOperator = jQuery.inArray( rule.operator, [ 'contains', 'starts_with', 'ends_with' ] ) !== -1; 185 186 // if we are looking for a specific value and this is not it, skip 187 if( fieldValue != rule.value && ! isRangeOperator && ! isStringOperator ) { 188 return; // continue 189 } 190 191 // force an empty value for unchecked items 192 if( ! $input.is( ':checked' ) ) { 193 fieldValue = ''; 194 } 195 // if the 'other' choice is selected, get the value from the 'other' text input 196 else if ( fieldValue == 'gf_other_choice' ) { 197 fieldValue = jQuery( '#input_{0}_{1}_other'.gformFormat( formId, fieldId ) ).val(); 198 } 199 200 if( gf_matches_operation( fieldValue, rule.value, rule.operator ) ) { 201 isMatch = true; 202 return false; // break 203 } 204 205 } ); 206 207 return isMatch; 208} 209 210/** 211 * Check if a collection of checkable inputs has any checked, 212 * or if they are all unchecked. 213 * 214 * @param {jQuery} $inputs A collection of inputs to check. 215 * 216 * @returns {boolean} 217 */ 218function gf_is_checkable_empty( $inputs ) { 219 var isEmpty = true; 220 221 $inputs.each( function() { 222 if ( jQuery( this ).is( ':checked' ) ) { 223 isEmpty = false; 224 } 225 } ); 226 227 return isEmpty; 228} 229 230function gf_is_match_default( $input, rule, formId, fieldId ) { 231 232 var val = $input.val(), 233 values = ( val instanceof Array ) ? val : [ val ], // transform regular value into array to support multi-select (which returns an array of selected items) 234 matchCount = 0, 235 valuesLength = Math.max( values.length, 1 ); // jQuery 3.0: Make sure our length is at least 1 so that the following loop fires. 236 237 for( var i = 0; i < valuesLength; i++ ) { 238 239 var isPriceField = $input.closest( '.gfield_price' ).length > 0, 240 hasLabel = ! values[i] || ( isPriceField && values[i].indexOf( '|' ) >= 0 ), 241 fieldValue = gf_get_value( values[i], $input ); 242 243 var fieldNumberFormat = gf_get_field_number_format( rule.fieldId, formId, 'value' ); 244 if( fieldNumberFormat && ! hasLabel ) { 245 fieldValue = gf_format_number( fieldValue, fieldNumberFormat ); 246 } 247 248 var ruleValue = rule.value; 249 //if ( fieldNumberFormat ) { 250 // ruleValue = gf_format_number( ruleValue, fieldNumberFormat ); 251 //} 252 253 if( gf_matches_operation( fieldValue, ruleValue, rule.operator ) ) { 254 matchCount++; 255 } 256 257 } 258 259 // if operator is 'isnot', none of the values can match 260 var isMatch = rule.operator == 'isnot' ? matchCount == valuesLength : matchCount > 0; 261 262 return isMatch; 263} 264 265function gf_format_number( value, fieldNumberFormat ) { 266 267 decimalSeparator = '.'; 268 269 if( fieldNumberFormat == 'currency' ) { 270 decimalSeparator = gform.Currency.getDecimalSeparator( 'currency' ); 271 } else if( fieldNumberFormat == 'decimal_comma' ) { 272 decimalSeparator = ','; 273 } else if( fieldNumberFormat == 'decimal_dot' ) { 274 decimalSeparator = '.'; 275 } 276 277 // transform to a decimal dot number 278 value = gform.Currency.cleanNumber( value, '', '', decimalSeparator ); 279 280 /** 281 * Looking at format specified by wp locale creates issues. When performing conditional logic, all numbers will be formatted to decimal dot and then compared that way. AC 282 */
283 // now transform to number specified by locale 284 // if( window['gf_number_format'] && window['gf_number_format'] == 'decimal_comma' ) { 285 // value = gformFormatNumber( value, -1, ',', '.' ); 286 // } 287 288 if( ! value ) { 289 value = 0; 290 } 291 292 number = value.toString(); 293 294 return number; 295} 296 297function gf_try_convert_float(text){ 298 299 /* 300 * The only format that should matter is the field format. Attempting to do this by WP locale creates a lot of issues with consistency. 301 * var format = window["gf_number_format"] == "decimal_comma" ? "decimal_comma" : "decimal_dot"; 302 */ 303 304 var format = 'decimal_dot'; 305 if( gformIsNumeric( text, format ) ) { 306 var decimal_separator = format == "decimal_comma" ? "," : "."; 307 return gform.Currency.cleanNumber( text, "", "", decimal_separator ); 308 } 309 310 return text; 311} 312 313function gf_matches_operation(val1, val2, operation){ 314 val1 = val1 ? val1.toLowerCase() : ""; 315 val2 = val2 ? val2.toLowerCase() : ""; 316 317 switch(operation){ 318 case "is" : 319 return val1 == val2; 320 break; 321 322 case "isnot" : 323 return val1 != val2; 324 break; 325 326 case ">" : 327 val1 = gf_try_convert_float(val1); 328 val2 = gf_try_convert_float(val2); 329 330 return gform.utils.isNumber(val1) && gform.utils.isNumber(val2) ? val1 > val2 : false; 331 break; 332 333 case "<" : 334 val1 = gf_try_convert_float(val1); 335 val2 = gf_try_convert_float(val2); 336 337 return gform.utils.isNumber(val1) && gform.utils.isNumber(val2) ? val1 < val2 : false; 338 break; 339 340 case "contains" : 341 return val1.indexOf(val2) >=0; 342 break; 343 344 case "starts_with" : 345 return val1.indexOf(val2) ==0; 346 break; 347 348 case "ends_with" : 349 var start = val1.length - val2.length; 350 if(start < 0) 351 return false; 352 353 var tail = val1.substring(start); 354 return val2 == tail; 355 break; 356 } 357 return false; 358} 359 360function gf_get_value( val, $input ) { 361 if ( ! val ) { 362 return ''; 363 } 364 365 // Selection pricing fields are formatted as value|price. Split on the | to get the field label or value that is in the first position. 366 // For all other pricing fields, splitting on the | won't have any effect. 367 if ( $input && $input.closest( '.gfield_price' ).length ) { 368 val = gformParseChoiceValue( val )['name']; 369 } 370 371 return val; 372} 373 374function gf_do_field_action(formId, action, fieldId, isInit, callback){ 375 var conditional_logic = window["gf_form_conditional_logic"][formId]; 376 var dependent_fields = conditional_logic["dependents"][fieldId]; 377 378 for(var i=0; i < dependent_fields.length; i++){ 379 var targetId = fieldId == 0 ? "#gform_submit_button_" + formId : "#field_" + formId + "_" + depen
379dent_fields[i]; 380 var defaultValues = conditional_logic["defaults"][dependent_fields[i]]; 381 382 //calling callback function on the last dependent field, to make sure it is only called once 383 do_callback = (i+1) == dependent_fields.length ? callback : null; 384 385 /** 386 * Allow add-ons to abort gf_do_action() function. 387 * 388 * @since 2.6.2 389 * 390 * @param bool $doAbort The value being filtered. True to abort conditional logic action, false to continue. Defaults to false. 391 * @param string $action The conditional logic action that will be performed. Possible values: show or hide 392 * @param string $targetId HTML element id that will be the targed of the conditional logic action. 393 * @param bool $doAnimation True to perform animation while showing/hiding field. False to hide/show field without animation. 394 * @param array $defaultValue Array containg default field values. 395 * @param bool $isInit True if form is being initialized (i.e. before user has interacted with any input). False otherwise. 396 * @param array $formId The current form ID. 397 * @param func $do_callback Callback function to be executed after conditional logic is executed. 398 */ 399 let abort = gform.applyFilters( 'gform_abort_conditional_logic_do_action', false, action, targetId, conditional_logic[ "animation" ], defaultValues, isInit, formId, do_callback ); 400 if ( ! abort ) { 401 gf_do_action( action, targetId, conditional_logic[ "animation" ], defaultValues, isInit, do_callback, formId ); 402 } else if ( do_callback ) { 403 do_callback(); 404 } 405 406 gform.doAction('gform_post_conditional_logic_field_action', formId, action, targetId, defaultValues, isInit); 407 } 408} 409 410function gf_do_next_button_action(formId, action, fieldId, isInit){ 411 var conditional_logic = window["gf_form_conditional_logic"][formId]; 412 var targetId = "#gform_next_button_" + formId + "_" + fieldId; 413 414 /** 415 * Allow add-ons to abort gf_do_action() function. 416 * 417 * @since 2.6.2 418 * 419 * @param bool $doAbort The value being filtered. True to abort conditional logic action, false to continue. Defaults to false. 420 * @param string $action The conditional logic action that will be performed. Possible values: show or hide 421 * @param string $targetId HTML element id that will be the targed of the conditional logic action. 422 * @param bool $doAnimation True to perform animation while showing/hiding field. False to hide/show field without animation. 423 * @param array $defaultValue Array containg default field values. 424 * @param bool $isInit True if form is being initialized (i.e. before user has interacted with any input). False otherwise. 425 * @param array $formId The current form ID. 426 * @param func $do_callback Callback function to be executed after conditional logic is executed. 427 */ 428 let abort = gform.applyFilters( 'gform_abort_conditional_logic_do_action', false, action, targetId, conditional_logic[ "animation" ], null, isInit, formId, null ); 429 if ( ! abort ) { 430 gf_do_action( action, targetId, conditional_logic[ "animation" ], null, isInit, null, formId ); 431 } 432} 433 434function gf_do_action(action, targetId, useAnimation, defaultValues, isInit, callback, formId){ 435 var $target = jQuery( targetId ); 436 437 /** 438 * Do not re-enable inputs that are disabled by default. Check if field's inputs have been assessed. If not, add 439 * designator class so these inputs are exempted below. 440 */ 441 if( ! $target.data( 'gf-disabled-assessed' ) ) { 442 $target.find( ':input:disabled' ).addClass( 'gf-default-disabled' ); 443 $target.data( 'gf-disabled-assessed', true ); 444 } 445 446 // honeypot should not be impacted by conditional logic. 447 if( $target.hasClass( 'gfield--type-honeypot') ) { 448 return; 449 } 450 451 if(action == "show"){ 452 // reset tabindex for selects 453 $target.find( 'select' ).each( function() { 454 var $select = jQuery( this ); 455 $select.attr( 'tabindex', $select.data( 'tabindex' ) ); 456 } ); 457 458 if(useAnimation && !isInit){ 459 if($target.length > 0){ 460 $target.find(':input:hidden:not(.gf-default-disabled)').prop( 'disabled', false ); 461 if ( $target.is( 'input[type="submit"]' ) || $target.hasClass( 'gform_next_button' ) ) { 462 gf_show_button( $target ); 463 } 464 $target.slideDown(callback); 465 $target.attr( 'data-conditional-logic', 'visible' ); 466 } else if(callback){ 467 callback(); 468 } 469 } 470 else{ 471 var display = $target.data('gf_display'); 472 473 // set display if previous (saved) display isn't set for any reason 474 if ( display == '' || display == 'none' ){ 475 display = '1' === gf_legacy.is_legacy ? 'list-item' : 'block'; 476 } 477 $target.find(':input:hidden:not(.gf-default-disabled)').prop( 'disabled', false ).attr( 'data-conditional-logic', 'visible' ); 478 479 // Handle conditional submit and next buttons. 480 if ( $target.is( 'input[type="submit"]' ) || $target.hasClass( 'gform_next_button' ) ) { 481 gf_show_button( $target ); 482 } else { 483 $target.css( 'display', display );
484 if( display == 'none' ) { 485 $target.attr( 'data-conditional-logic', 'hidden' ); 486 } else { 487 $target.attr( 'data-conditional-logic', 'visible' ); 488 } 489 } 490 491 if(callback){ 492 callback(); 493 } 494 } 495 } 496 else{ 497 498 //if field is not already hidden, reset its values to the default 499 var child = $target.children().first(); 500 if (child.length > 0){ 501 var reset = gform.applyFilters('gform_reset_pre_conditional_logic_field_action', true, formId, targetId, defaultValues, isInit); 502 503 if(reset && !gformIsHidden(child)){ 504 gf_reset_to_default(targetId, defaultValues); 505 } 506 } 507 508 // remove tabindex and stash as a data attr for selects 509 $target.find( 'select' ).each( function() { 510 var $select = jQuery( this ); 511 $select.data( 'tabindex', $select.attr( 'tabindex' ) ).removeAttr( 'tabindex' ); 512 } ); 513 514 //Saving existing display so that it can be reset when showing the field 515 if( ! $target.data('gf_display') ){ 516 $target.data('gf_display', $target.css('display')); 517 } 518 519 if(useAnimation && !isInit){ 520 if( $target.is( 'input[type="submit"]' ) || $target.hasClass( 'gform_next_button' ) ) { 521 gf_hide_button( $target ); 522 } else if ( $target.length > 0 && $target.is( ":visible" ) ) { 523 $target.slideUp( callback ); 524 $target.attr( 'data-conditional-logic', 'hidden' ); 525 } else if ( callback ) { 526 callback(); 527 } 528 } else{ 529 530 // Handle conditional submit and next buttons. 531 if ( $target.is( 'input[type="submit"]' ) || $target.hasClass( 'gform_next_button' ) ) { 532 gf_hide_button( $target ); 533 } else { 534 $target.css( 'display', 'none' ); 535 $target.attr( 'data-conditional-logic', 'hidden' ); 536 } 537 $target.find(':input:hidden:not(.gf-default-disabled)').attr( 'disabled', 'disabled' ); 538 if(callback){ 539 callback(); 540 } 541 } 542 } 543 544} 545 546function gf_show_button( $target ) { 547 $target.prop( 'disabled', false ).css( 'display', '' ); 548 $target.attr( 'data-conditional-logic', 'visible' ); 549 if ( '1' == gf_legacy.is_legacy ) { 550 // for legacy markup, remove screen reader class. 551 $target.removeClass( 'screen-reader-text' ); 552 } 553 554 // Sometimes the next button is pretending to be a submit button, so it needs conditional logic too. 555 var fauxSubmitButton = jQuery( 'input.gform_next_button[type="button"][value="Submit"]' ); 556 if ( fauxSubmitButton ) { 557 fauxSubmitButton.prop( 'disabled', false ).css( 'display', '' ); 558 fauxSubmitButton.attr( 'data-conditional-logic', 'visible' ); 559 } 560} 561 562function gf_hide_button( $target ) { 563 $target.attr( 'disabled', 'disabled' ).hide(); 564 $target.attr( 'data-conditional-logic', 'hidden' ); 565 if ( '1' === gf_legacy.is_legacy ) { 566 // for legacy markup, let screen readers read the button. 567 $target.addClass( 'screen-reader-text' ); 568 } 569 570 // Sometimes the next button is pretending to be a submit button, so it needs conditional logic too. 571 var fauxSubmitButton = jQuery( 'input.gform_next_button[type="button"][value="Submit"]' ); 572 if ( fauxSubmitButton ) { 573 fauxSubmitButton.attr( 'disabled', 'disabled' ).hide(); 574 fauxSubmitButton.attr( 'data-conditional-logic', 'hidden' ); 575 } 576} 577 578function gf_reset_to_default(targetId, defaultValue){ 579 580 var $target = jQuery( targetId ); 581 if( $target.hasClass('gfield_shipping') || $target.hasClass('gfield_total') || 582 $target.hasClass('gfield--type-shipping') || $target.hasClass('gfield--type-total') ) { 583 return; 584 } 585 586 var dateFields = jQuery( targetId ).find( '.gfield_date_month input, .gfield_date_day input, .gfield_date_year input, .gfield_date_dropdown_month select, .gfield_date_dropdown_day select, .gfield_date_dropdown_year select' ); 587 if( dateFields.length > 0 ) { 588 589 dateFields.each( function(){ 590 591 var element = jQuery( this ); 592 593 // defaultValue is associative array (i.e. [ m: 1, d: 13, y: 1987 ] ) 594 if( defaultValue ) { 595 596 var key = 'd'; 597 if (element.parents().hasClass('gfield_date_month') || element.parents().hasClass('gfield_date_dropdown_month') ){ 598 key = 'm'; 599 } 600 else if(element.parents().hasClass('gfield_date_year') || element.parents().hasClass('gfield_date_dropdown_year') ){ 601 key = 'y'; 602 } 603 604 val = defaultValue[ key ]; 605 606 } 607 else{ 608 val = ""; 609 } 610 611 if(element.prop("tagName") == "SELECT" && val != '' ) 612 val = parseInt(val, 10); 613 614 615 if(element.val() != val) 616 element.val(val).trigger("change"); 617 else 618 element.val(val); 619 620 }); 621 622 return; 623 } 624 625 //cascading down conditional logic to children to support nested conditions 626 //text fields and drop downs, filter out list field text fields name with "_shim" 627 var target = jQuery(targetId).find( 'select, input[type="text"]:not([id*="_shim"]), input[type="number"], input[type="hidden"], input[type="email"], input[type="tel"], input[type="url"], textarea' ); 628 var target_index = 0; 629 630 // When a List field is hidden via conditional logic during a page submission, the markup
630will be reduced to a 631 // single row. Add enough rows/inputs to satisfy the default value. 632 if( defaultValue && target.parents( '.ginput_list' ).length > 0 && target.length < defaultValue.length ) { 633 while( target.length < defaultValue.length ) { 634 gformAddListItem( target.eq( 0 ), 0 ); 635 target = jQuery(targetId).find( 'select, input[type="text"]:not([id*="_shim"]), input[type="number"], textarea' ); 636 } 637 } 638 639 target.each(function(){ 640 641 var val = ""; 642 643 var element = jQuery(this); 644 645 // Only reset Single Product and Shipping hidden inputs. 646 if( element.is( '[type="hidden"]' ) && ! gf_is_hidden_pricing_input( element ) ) { 647 return; 648 } 649 650 //get name of previous input field to see if it is the radio button which goes with the "Other" text box 651 //otherwise field is populated with input field name 652 var radio_button_name = element.prevAll("input").first().attr("value"); 653 if(radio_button_name == "gf_other_choice"){ 654 val = element.attr("value"); 655 } 656 else if( Array.isArray( defaultValue ) && ! element.is( 'select[multiple]' ) ) { 657 val = defaultValue[target_index]; 658 } 659 else if(jQuery.isPlainObject(defaultValue)){ 660 val = defaultValue[element.attr("name")]; 661 if( ! val && element.attr( 'id' ) ) { 662 // 'input_123_3_1' => '3.1' 663 var inputId = element.attr( 'id' ).split( '_' ).slice( 2 ).join( '.' ); 664 val = defaultValue[ inputId ]; 665 } 666 if( ! val && element.attr( 'name' ) && element.attr( 'type' ) != 'email' ) { 667 var inputId = element.attr( 'name' ).split( '_' )[1]; 668 val = defaultValue[ inputId ]; 669 } 670 } 671 else if(defaultValue){ 672 val = defaultValue; 673 } 674 675 if( element.is('select:not([multiple])') && ! val ) { 676 val = element.find( 'option' ).not( ':disabled' ).eq(0).val(); 677 } 678 679 if(element.val() != val) { 680 element.val(val).trigger('change'); 681 if (element.is('select') && element.next().hasClass('chosen-container')) { 682 element.trigger('chosen:updated'); 683 } 684 // Check for Single Product & Shipping input and force visual price update. 685 if( gf_is_hidden_pricing_input( element ) ) { 686 var ids = gf_get_ids_by_html_id( element.parents( '.gfield' ).attr( 'id' ) ); 687 jQuery( '#input_' + ids[0] + '_' + ids[1] ).text( gformFormatMoney( element.val() ) ); 688 element.val( gformFormatMoney( element.val() ) ); 689 } 690 } 691 else{ 692 element.val(val); 693 } 694 695 target_index++; 696 }); 697 698 //checkboxes and radio buttons 699 var elements = jQuery(targetId).find('input[type="radio"], input[type="checkbox"]:not(".copy_values_activated")'); 700 701 elements.each(function(){ 702 703 //is input currently checked? 704 var isChecked = jQuery(this).is(':checked') ? true : false; 705 706 //does input need to be marked as checked or unchecked? 707 var doCheck = defaultValue ? jQuery.inArray(jQuery(this).attr('id'), defaultValue) > -1 : false; 708 709 //if value changed, trigger click event 710 if(isChecked != doCheck){ 711 //setting input as checked or unchecked appropriately 712 713 if(jQuery(this).attr("type") == "checkbox"){ 714 jQuery(this).trigger('click'); 715 } 716 else{ 717 jQuery(this).prop('checked', doCheck).change(); 718 } 719 720 } 721 }); 722 723} 724 725function gf_is_hidden_pricing_input( element ) { 726 727 // Check for Single Product fields. 728 if( element.attr( 'id' ) && element.attr( 'id' ).indexOf( 'ginput_base_price' ) === 0 ) { 729 return true; 730 } 731 732 if( element.attr( 'type' ) !== 'hidden' ) { 733 return false; 734 } 735 736 // Check for Shipping fields. 737 return element.parents( '.gfield_shipping' ).length; 738}
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.