Advertisement
Guest User

Untitled

a guest
Jan 13th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.46 KB | None | 0 0
  1.     /**
  2.      * Form VALIDATION
  3.      */
  4.  
  5.     var stockInputs = $("#option_31, #option_32, #option_33");
  6.     stockInputs
  7.         .keypress(function (e) {
  8.             if (String.fromCharCode(e.keyCode).match(/[^0-9]/g)) return false;
  9.         })
  10.         .attr({
  11.             "placeholder" : "Podaj wymiary z dokładnością do 5 cm"
  12.         });
  13.  
  14.     /** */
  15.  
  16.    $.validator.addMethod('totalCheck', function(value, element, params) {
  17.         var field_1 = $('input[name="' + params[0] + '"]').val(),
  18.             field_2 = $('input[name="' + params[1] + '"]').val();
  19.         var total = parseInt(field_1) + parseInt(field_2);
  20.         if (total > 140) {
  21.             console.log("Greater than 140!")
  22.             return false;
  23.         } else {
  24.             return parseInt(field_1) + parseInt(field_2);
  25.         }
  26.        
  27.     }, "Suma boków B+C nie może być większa niż 140 cm!");
  28.  
  29.  
  30.     $(".shop_product_from_cat_29 .form-basket").submit(function(e) {
  31.         e.preventDefault();
  32.     }).validate({
  33.         rules: {
  34.             option_31: {
  35.                 required: true,
  36.                 min: 30,
  37.                 max: 230,
  38.                 step: 5
  39.             },
  40.             option_32: {
  41.                 required: true,
  42.                 min: 30,
  43.                 max: 110,
  44.                 step: 5,
  45.             },
  46.             option_33: {
  47.                 required: true,
  48.                 min: 30,
  49.                 max: 110,
  50.                 step: 5,
  51.                 totalCheck: ['option_32', 'option_33']
  52.             }
  53.         },
  54.         messages: {
  55.             option_31: {
  56.                 required: "Pole wymagane",
  57.                 min: "Minimalna szerokość to 30 cm",
  58.                 max: "Maksymalna szerokość to 230 cm",
  59.                 step: "Podawaj wymiary co 5 cm!"
  60.             },
  61.             option_32: {
  62.                 required: "Pole wymagane",
  63.                 min: "Minimalna głębokość to 30 cm",
  64.                 max: "Maksymalna głębokość to 110 cm",
  65.                 step: "Podawaj wymiary co 5 cm!"
  66.             },
  67.             option_33: {
  68.                 required: "Pole wymagane",
  69.                 min: "Minimalna wysokość to 30 cm",
  70.                 max: "Maksymalna wysokość to 110 cm",
  71.                 step: "Podawaj wymiary co 5 cm!"
  72.             }
  73.         },
  74.         submitHandler: function (form) {
  75.             alert('sfasf');
  76.             form.submit();
  77.             return false;  
  78.            
  79.         }
  80.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement