Advertisement
Guest User

Funçao do capiroto

a guest
Oct 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.43 KB | None | 0 0
  1.     jQuery(document).ready(function(){
  2.         var $ = jQuery;
  3.         $('.stm_add_car_form .stm_add_car_form_1 .stm-form-1-selects select:not(.hide)').select2().on('change', function(){
  4.  
  5.             /*Remove disabled*/
  6.  
  7.             var stmCurVal = $(this).val();
  8.             var stmCurSelect = $(this).attr('name');
  9.             stmCurSelect = stmCurSelect.match(/\[(.*?)\]/)[1];
  10.  
  11.             if (stmTaxRelations[stmCurSelect]) {
  12.  
  13.  
  14.                 var key = stmTaxRelations[stmCurSelect]['dependency'];
  15.                 $('select[name="stm_f_s[' + key + ']"]').val('');
  16.                 if(stmCurVal == '') {
  17.                     $('select[name="stm_f_s[' + key + ']"] > option').each(function () {
  18.                         $(this).removeAttr('disabled');
  19.                     });
  20.                 } else {
  21.                     var allowedTerms = stmTaxRelations[stmCurSelect][stmCurVal];
  22.  
  23.                     if(typeof(allowedTerms) == 'object') {
  24.                         $('select[name="stm_f_s[' + key + ']"] > option').removeAttr('disabled');
  25.  
  26.                         $('select[name="stm_f_s[' + key + ']"] > option').each(function () {
  27.                             var optVal = $(this).val();
  28.                             if (optVal != '' && $.inArray(optVal, allowedTerms) == -1) {
  29.                                 $(this).attr('disabled', '1');
  30.                             }
  31.                         });
  32.                     } else {
  33.                         $('select[name="stm_f_s[' + key + ']"]').val(allowedTerms);
  34.                     }
  35.                 }
  36.  
  37.                 $('.stm_add_car_form .stm_add_car_form_1 .stm-form-1-selects select[name="stm_f_s[' + key + ']"]').select2("destroy");
  38.  
  39.                 $('.stm_add_car_form .stm_add_car_form_1 .stm-form1-intro-unit select[name="stm_f_s[' + key + ']"]').select2();
  40.             }
  41.         });
  42.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement