Advertisement
Guest User

Blah

a guest
Jul 15th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. jQuery(window).ready(function($) {
  2.  
  3. var// Setting up our target/selectors here. For uniformity as well as for maintability.
  4. 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';
  5. // where the tables are stored.
  6.  
  7. bind_on_load(); //Load Select handler.
  8.  
  9. $('.editor_menu_wrapper input[type="submit"] , .editor_menu_wrapper button.dummy_button').live("click", function(e) {
  10.  
  11. var ui_menu_button_value = $(this).attr('value');
  12. var ui_menu_button_pressed = this.textContent;
  13. var ui_menu_button_name = $(this).attr("name");
  14. var optional = {
  15.  
  16. url : verendus_core_form_obj.ajaxurl,
  17. type : "POST",
  18. dataType : 'html',
  19. data : {
  20.  
  21. action : "submit_the_formz",
  22. post_id : verendus_core_form_obj.company_post_id,
  23. security : verendus_core_form_obj.ajax_nonce,
  24. manual_submit : true,
  25. ui_menu_button_value : ui_menu_button_value,
  26. ui_menu_button_pressed : ui_menu_button_pressed,
  27. ui_menu_button_name : ui_menu_button_name,
  28.  
  29. },
  30.  
  31. beforeSend : function() {
  32.  
  33. $('#loadingDiv').show();
  34.  
  35. },
  36.  
  37. complete : function() {
  38.  
  39. $.when(populate_counties()).done(function() {
  40.  
  41. $('#loadingDiv').hide();
  42.  
  43. });
  44.  
  45. },
  46.  
  47. success : function(data) {
  48.  
  49. $(".editor_wrapper").empty();
  50.  
  51. $(".editor_wrapper").html(data);
  52.  
  53. },
  54.  
  55. };
  56.  
  57. e.preventDefault();
  58.  
  59. $(".editor_menu_wrapper").ajaxSubmit(optional);
  60.  
  61. });
  62.  
  63. $('.company_page_edit input[type="submit"], .company_page_edit_2 input[type="submit"]').live("click", function(e) {
  64.  
  65. var optional = {
  66.  
  67. url : verendus_core_form_obj.ajaxurl,
  68. type : "POST",
  69. dataType : 'html',
  70. data : {
  71.  
  72. action : "submit_the_formz",
  73. manual_submit : true,
  74.  
  75. },
  76.  
  77. beforeSend : function() {
  78.  
  79. $('#loadingDiv').show();
  80.  
  81. },
  82.  
  83. complete : function() {
  84.  
  85. $('#loadingDiv').hide();
  86.  
  87. },
  88.  
  89. };
  90.  
  91. e.preventDefault();
  92.  
  93. $(".acf-form").ajaxSubmit(optional);
  94.  
  95. });
  96.  
  97. //////////////////////////////// Our helper functions here ////////////////////////////////////////////////////////
  98.  
  99. function populate_counties() {
  100.  
  101. $(table_body).find('[data-field_name="select_state"]').each(function() {
  102.  
  103. var state = $(this).find('select').val();
  104. var field_key = $(this).find('select').attr("name");
  105. var appended_county_list = $(this).closest('tr.row').find('[data-field_name="select_a_county"] select');
  106.  
  107. $.ajax({
  108. type : "POST",
  109. url : verendus_core_form_obj.ajaxurl,
  110. data : {
  111.  
  112. nonce : verendus_core_form_obj.nonce,
  113. action : 'populate_counties',
  114. state : state,
  115. company_post_id : verendus_core_form_obj.company_post_id,
  116. field_key : field_key,
  117.  
  118. },
  119.  
  120. success : function(html) {
  121.  
  122. appended_county_list.html(html);
  123.  
  124. },
  125.  
  126. });
  127.  
  128. });
  129.  
  130. }
  131.  
  132. ///////////////////////////////////////////// Select Handler Portion iz herez /////////////////////////////////////////
  133.  
  134. function bind_on_load() {
  135. stateSelect.live('change', function() {
  136.  
  137. var state = $(this).val();
  138.  
  139. var currentCitySelect = $(this).closest('tr.row').find('[data-field_name="select_a_county"] select');
  140.  
  141. $.ajax({
  142. type : "POST",
  143. url : verendus_core_form_obj.ajaxurl,
  144. data : {
  145. action : 'populate_counties',
  146. state : state,
  147. nonce:verendus_core_form_obj.nonce,
  148. },
  149.  
  150. success : function(html) {
  151.  
  152. currentCitySelect.html(html);
  153.  
  154. },
  155.  
  156. error : function(html) {
  157.  
  158. },
  159.  
  160. beforeSend : function() {
  161.  
  162. $('#loadingDiv').show();
  163.  
  164. },
  165.  
  166. complete : function() {
  167.  
  168. $('#loadingDiv').hide();
  169.  
  170. }
  171. });
  172. });
  173.  
  174. countySelect.live('change', function() {
  175.  
  176. var CountiesSelected = $(this).parents('tr.row').find('[data-field_name="select_a_county"] select').val();
  177.  
  178. var ChangeZipSelect = $(this).closest('tr.row').find('[data-field_name="select_zip_codes"] select');
  179.  
  180. $.ajax({
  181. type : "POST",
  182. url : verendus_core_form_obj.ajaxurl,
  183. data : {
  184. action : 'populate_zip_list',
  185. CountiesSelected : CountiesSelected,
  186. nonce:verendus_core_form_obj.nonce,
  187. },
  188.  
  189. success : function(html) {
  190.  
  191. ChangeZipSelect.html(html);
  192.  
  193. },
  194.  
  195. beforeSend : function() {
  196.  
  197. $('#loadingDiv').show();
  198.  
  199. },
  200.  
  201. complete : function() {
  202.  
  203. $('#loadingDiv').hide();
  204.  
  205. }
  206.  
  207. });
  208. });
  209. }
  210.  
  211. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement