2

I am trying to copy a simple example from here: https://via-profit.github.io/js-form-validator/ But I get Uncaught SyntaxError: Unexpected token ':'

`

var formHandle = document.querySelector('#myform'),
    options: { //ERROR REFERS TO THIS LINE

        // set a custom rule
        rules: {
            milk: function (value) {
                return (value.trim().toLowerCase() === 'milk');
            }
        },

        // set a incorrect message text
        messages: {
            en: {
                milk: {
                    incorrect: 'This is not a Milk ;-)'
                }
            }
        }
    };

// Got to validation
new Validator(formHandle, function (err, res) {
    return res;

}, options);`

Am i doing something super dumb here? I copy and pasted there example. What have I done wrong?

1
  • The example is wrong. What re you trying to do? Commented Jun 16, 2020 at 1:57

2 Answers 2

3

I think documentation is wrong. It should be

var formHandle = document.querySelector('#myform');
var options = {

    // set a custom rule
    rules: {
...

Please try this. It will work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Annoying they provide an invalid example.
0

may be it is the back tick at the end of your last line -> }, options);`

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.