Advertisement
Guest User

settings

a guest
Jul 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener('DOMContentLoaded', function () {
  2.     $.validator.setDefaults({
  3.         highlight: function (element) {
  4.             $(element)
  5.                 .closest('.form-group')
  6.                 .addClass('has-warning');
  7.         },
  8.         unhighlight: function (element) {
  9.             $(element)
  10.                 .closest('.form-group')
  11.                 .removeClass('has-warning');
  12.         }
  13.     });
  14.  
  15.     $('#changeEmailForm').validate({
  16.         rules: {
  17.             password: {
  18.                 required: true,
  19.                 remote: {
  20.                     url: '/checkPassword',
  21.                     type: "GET",
  22.                     data: {
  23.                         password: function () {
  24.                             return $('#password').val();
  25.                         }
  26.                     }
  27.                 }
  28.             },
  29.             email: {
  30.                 required: true,
  31.                 email: true,
  32.                 remote: {
  33.                     url: '/checkEmailAtRegistering',
  34.                     type: "GET",
  35.                     data: {
  36.                         email: function () {
  37.                             return $('#email').val();
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.         },
  43.         messages: {
  44.             password: {
  45.                 remote: $.validator.format('Your password is incorrect')
  46.             },
  47.             email: {
  48.                 remote: $.validator.format('Email {0} exists in the database')
  49.             }
  50.         },
  51.         submitHandler: function () {
  52.             changeEmail()
  53.         }
  54.     });
  55.  
  56.     function changeEmail() {
  57.         console.log("Event");
  58.         $.ajax({
  59.             type: 'PUT',
  60.             url: '/changeEmail',
  61.             data: {
  62.                 email: $('#email').val()
  63.             },
  64.             success: function (result) {
  65.                 console.log('function');
  66.             }
  67.         });
  68.     }
  69. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement