Advertisement
dantry

validasi-form.js

May 23rd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.  
  3.  
  4.     $('#register')
  5.         .bootstrapValidator({
  6.             message: 'This value is not valid',
  7.             feedbackIcons: {
  8.                 valid: 'glyphicon glyphicon-ok',
  9.                 invalid: 'glyphicon glyphicon-remove',
  10.                 validating: 'glyphicon glyphicon-refresh'
  11.             },
  12.             fields: {
  13.                 firstName: {
  14.                     validators: {
  15.                         notEmpty: {
  16.                             message: 'firstName tidak boleh kosong'
  17.                         }
  18.                     }
  19.                 },
  20.                 lastName: {
  21.                     validators: {
  22.                         notEmpty: {
  23.                             message: 'The last name is tidak boleh kosong'
  24.                         }
  25.                     }
  26.                 },
  27.                 username: {
  28.                     message: 'Username tidak sah',
  29.                     validators: {
  30.                         notEmpty: {
  31.                             message: 'The username is required and cannot be empty'
  32.                         },
  33.                         stringLength: {
  34.                             min: 6,
  35.                             max: 30,
  36.                             message: 'Username minimal 6 karakter atau lebih'
  37.                         },
  38.                         regexp: {
  39.                             regexp: /^[a-zA-Z0-9_\.]+$/,
  40.                             message: 'Username tidak boleh mengandung alphabetic dan angka,imputkan huruf'
  41.                         },
  42. //                        remote: {
  43. //                            url: 'remote.php',
  44. //                            message: 'The username is not available'
  45. //                        },
  46.                         different: {
  47.                             field: 'password',
  48.                             message: 'The username and password cannot be the same as each other'
  49.                         }
  50.                     }
  51.                 },
  52.                 email: {
  53.                     validators: {
  54.                         emailAddress: {
  55.                             message: 'Email tidak sah'
  56.                         }
  57.                     }
  58.                 },
  59.                 password: {
  60.                     validators: {
  61.                         notEmpty: {
  62.                             message: 'Password tidak boleh kosong'
  63.                         },
  64.                         identical: {
  65.                             field: 'confirmPassword',
  66.                             message: 'The password and its confirm are not the same'
  67.                         },
  68.                         different: {
  69.                             field: 'username',
  70.                             message: 'The password cannot be the same as username'
  71.                         }
  72.                     }
  73.                 },
  74.                 confirmPassword: {
  75.                     validators: {
  76.                         notEmpty: {
  77.                             message: 'The confirm password is required and cannot be empty'
  78.                         },
  79.                         identical: {
  80.                             field: 'password',
  81.                             message: 'The password and its confirm are not the same'
  82.                         },
  83.                         different: {
  84.                             field: 'username',
  85.                             message: 'The password cannot be the same as username'
  86.                         }
  87.                     }
  88.                 },
  89.                 gender: {
  90.                     validators: {
  91.                         notEmpty: {
  92.                             message: 'The gender is required'
  93.                         }
  94.                     }
  95.                 },
  96.                 'languages[]': {
  97.                     validators: {
  98.                         notEmpty: {
  99.                             message: 'Please specify at least one language you can speak'
  100.                         }
  101.                     }
  102.                 },
  103.                 'programs[]': {
  104.                     validators: {
  105.                         choice: {
  106.                             min: 2,
  107.                             max: 4,
  108.                             message: 'Please choose 2 - 4 programming languages you are good at'
  109.                         }
  110.                     }
  111.                 }
  112.             }
  113.         })
  114.         .on('error.form.bv', function(e) {
  115.             console.log('error.form.bv');
  116.  
  117.             // You can get the form instance and then access API
  118.             var $form = $(e.target);
  119.             console.log($form.data('bootstrapValidator').getInvalidFields());
  120.  
  121.             // If you want to prevent the default handler (bootstrapValidator._onError(e))
  122.             // e.preventDefault();
  123.         })
  124.         .on('success.form.bv', function(e) {
  125.             console.log('success.form.bv');
  126.  
  127.             // If you want to prevent the default handler (bootstrapValidator._onSuccess(e))
  128.             // e.preventDefault();
  129.         })
  130.         .on('error.field.bv', function(e, data) {
  131.             console.log('error.field.bv -->', data);
  132.         })
  133.         .on('success.field.bv', function(e, data) {
  134.             console.log('success.field.bv -->', data);
  135.         })
  136.         .on('status.field.bv', function(e, data) {
  137.             // I don't want to add has-success class to valid field container
  138.             data.element.parents('.form-group').removeClass('has-success');
  139.  
  140.             // I want to enable the submit button all the time
  141.             data.bv.disableSubmitButtons(false);
  142.         });
  143.  
  144. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement