Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($) {
- var acffield_committee = '#acf-field_5c646d5e7f431';
- var acffield_location = '#acf-field_5c64709d7f436';
- // Add default 'Select one'
- $( acffield_committee ).prepend( $('<option></option>').val('0').html('Select Committee').attr({ selected: 'selected', disabled: 'disabled'}) );
- /**
- * Get committee options on select menu change
- *
- */
- $( acffield_committee ).change(function () {
- var selected_committee = ''; // Selected value
- var my_selected_committee = pl_vars.selected_committee;
- var my_selected_location = pl_vars.selected_location;
- // Get selected value
- $( '#acf-field_5c646d5e7f431 option:selected' ).each(function() {
- selected_committee += $( this ).text();
- });
- $( acffield_location ).attr( 'disabled', 'disabled' );
- // If default is not selected get default location for selected committee
- if( selected_committee != 'Select Committee' ) {
- // Send AJAX request
- data = {
- action: 'pl_add_location',
- pl_nonce: pl_vars.pl_nonce,
- committee: selected_committee,
- };
- // Get response and populate location field
- $.post( ajaxurl, data, function(response) {
- if( response ){
- // Disable Location field until country is selected
- //$( acffield_location ).html( $('<option></option>').val('0').html('Select Area').attr({ selected: 'selected', disabled: 'disabled'}) );
- $( acffield_location ).attr({ selected: 'selected', disabled: 'disabled'});
- // Add areas to select field options
- $.each(response, function(val, text) {
- $( acffield_location ).val(text);
- });
- // No idea where this goes. Need to save selected_committee choice as well as value for location (whether it's prepopulated or something new typed in by user.)
- $('.my-select option[value="' + my_selected_location +'"]').attr('selected', 'selected');
- // Enable 'Select Location' field
- $( acffield_location ).removeAttr( 'disabled' );
- };
- });
- }
- }).change();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement