Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(window).ready(function($) {
- var// Setting up our target/selectors here. For uniformity as well as for maintability.
- stateSelect = $('[data-field_name="select_state"] select'), countySelect = $('[data-field_name="select_a_county"] select'), zipSelect = $('[data-field_name="select_zip_codes"] select'), table_body = '.repeater > .acf-input-table > tbody > tr.row';
- // where the tables are stored.
- bind_on_load(); //Load Select handler.
- $('.editor_menu_wrapper input[type="submit"] , .editor_menu_wrapper button.dummy_button').live("click", function(e) {
- var ui_menu_button_value = $(this).attr('value');
- var ui_menu_button_pressed = this.textContent;
- var ui_menu_button_name = $(this).attr("name");
- var optional = {
- url : verendus_core_form_obj.ajaxurl,
- type : "POST",
- dataType : 'html',
- data : {
- action : "submit_the_formz",
- post_id : verendus_core_form_obj.company_post_id,
- security : verendus_core_form_obj.ajax_nonce,
- manual_submit : true,
- ui_menu_button_value : ui_menu_button_value,
- ui_menu_button_pressed : ui_menu_button_pressed,
- ui_menu_button_name : ui_menu_button_name,
- },
- beforeSend : function() {
- $('#loadingDiv').show();
- },
- complete : function() {
- $.when(populate_counties()).done(function() {
- $('#loadingDiv').hide();
- });
- },
- success : function(data) {
- $(".editor_wrapper").empty();
- $(".editor_wrapper").html(data);
- },
- };
- e.preventDefault();
- $(".editor_menu_wrapper").ajaxSubmit(optional);
- });
- $('.company_page_edit input[type="submit"], .company_page_edit_2 input[type="submit"]').live("click", function(e) {
- var optional = {
- url : verendus_core_form_obj.ajaxurl,
- type : "POST",
- dataType : 'html',
- data : {
- action : "submit_the_formz",
- manual_submit : true,
- },
- beforeSend : function() {
- $('#loadingDiv').show();
- },
- complete : function() {
- $('#loadingDiv').hide();
- },
- };
- e.preventDefault();
- $(".acf-form").ajaxSubmit(optional);
- });
- //////////////////////////////// Our helper functions here ////////////////////////////////////////////////////////
- function populate_counties() {
- $(table_body).find('[data-field_name="select_state"]').each(function() {
- var state = $(this).find('select').val();
- var field_key = $(this).find('select').attr("name");
- var appended_county_list = $(this).closest('tr.row').find('[data-field_name="select_a_county"] select');
- $.ajax({
- type : "POST",
- url : verendus_core_form_obj.ajaxurl,
- data : {
- nonce : verendus_core_form_obj.nonce,
- action : 'populate_counties',
- state : state,
- company_post_id : verendus_core_form_obj.company_post_id,
- field_key : field_key,
- },
- success : function(html) {
- appended_county_list.html(html);
- },
- });
- });
- }
- ///////////////////////////////////////////// Select Handler Portion iz herez /////////////////////////////////////////
- function bind_on_load() {
- stateSelect.live('change', function() {
- var state = $(this).val();
- var currentCitySelect = $(this).closest('tr.row').find('[data-field_name="select_a_county"] select');
- $.ajax({
- type : "POST",
- url : verendus_core_form_obj.ajaxurl,
- data : {
- action : 'populate_counties',
- state : state,
- nonce:verendus_core_form_obj.nonce,
- },
- success : function(html) {
- currentCitySelect.html(html);
- },
- error : function(html) {
- },
- beforeSend : function() {
- $('#loadingDiv').show();
- },
- complete : function() {
- $('#loadingDiv').hide();
- }
- });
- });
- countySelect.live('change', function() {
- var CountiesSelected = $(this).parents('tr.row').find('[data-field_name="select_a_county"] select').val();
- var ChangeZipSelect = $(this).closest('tr.row').find('[data-field_name="select_zip_codes"] select');
- $.ajax({
- type : "POST",
- url : verendus_core_form_obj.ajaxurl,
- data : {
- action : 'populate_zip_list',
- CountiesSelected : CountiesSelected,
- nonce:verendus_core_form_obj.nonce,
- },
- success : function(html) {
- ChangeZipSelect.html(html);
- },
- beforeSend : function() {
- $('#loadingDiv').show();
- },
- complete : function() {
- $('#loadingDiv').hide();
- }
- });
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement