Untitled
webwizards
plain_text
2 months ago
2.2 kB
11
Indexable
add_action('wp_head', function(){
?>
<script>
function updatePECFieldRequirements() {
// Get current values
var selectedRole = jQuery('#b2bking_registration_roles_dropdown').val();
var selectedCountry = jQuery('#b2bking_custom_field_1370').val();
// Get PEC field elements
var pecField = jQuery('#b2bking_field_1444');
var pecLabel = jQuery('label[for="b2bking_field_1444"]');
var shouldBeRequired = false;
// Required if Italy is selected
if (selectedCountry === 'IT') {
shouldBeRequired = true;
}
// Update field requirements
if (shouldBeRequired) {
// Add required attribute and asterisk
pecField.prop('required', true);
pecField.addClass('b2bking_custom_field_req_required');
// Add asterisk if not already present
if (pecLabel.find('.required').length === 0) {
pecLabel.append('<span class="required"> *</span>');
}
} else {
// Remove required attribute and asterisk
pecField.prop('required', false);
pecField.removeClass('b2bking_custom_field_req_required');
// Remove asterisk
pecLabel.find('.required').remove();
}
// Set field as visible
jQuery('.b2bking_custom_registration_container_field_1444').css('display','block');
}
// Run the function when page loads
jQuery(document).ready(function() {
// Initial check
setTimeout(updatePECFieldRequirements, 50);
// Run on dropdown or country change
jQuery('#b2bking_registration_roles_dropdown').on('change', function() {
setTimeout(updatePECFieldRequirements, 50);
});
jQuery('#b2bking_custom_field_1370').on('change', function() {
setTimeout(updatePECFieldRequirements, 50);
});
});
</script>
<?php
});Editor is loading...
Leave a Comment