0

Can't seem to get jQuery validate pluging to work with Typescript.

This works:

$(document).ready(function() {
    alert('hi')
})

This gives a compilation error: ' Property 'validate' does not exist on type 'JQuery'.'

$(document).ready(function() {
    $("#form").validate();
})

Tried installing: npm install --save @types/jquery.validation

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="icon" href="/favicon.png" type="image/x-icon">
    <link rel="stylesheet" href="/styles.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"></script>
    <title>Document</title>
</head>
<body>
    <section class="section">
        <div class="wrapper"></div>
        <form class="form__box" id="form">
            <label>Username</label>
            <input type="text" name="username">
            <label>E-mail</label>
            <input name="email" type="text">
            <label>Password</label>
            <input name="password" type="text">
            <button>SUBMIT</button>
        </form>
    </section>
    <script src="/scripts.js">   
    </script>
</body>
</html>

$(document).ready(function() {
    $("#form").validate();
})
3
  • Yes. Still not working. Forgot to remove parenthesis after trying to cast it type 'any'. Doesn't make a difference unfortunately. Commented Jan 31, 2023 at 22:11
  • Try: stackoverflow.com/a/58423755/594235 Commented Jan 31, 2023 at 22:14
  • This seem to be an issue with how you're using Typescript as opposed to anything to do with jQuery Validate. Commented Jan 31, 2023 at 22:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.