0

I have the below ready function.

$(document).ready(function() {
    var window = $("#window");
    viewModel.validator = $("#Details").kendoValidator().data("kendoValidator")({
        rules: {
            checkPersonContactInfo: function (input) {
                if (intakeView.viewModel.get("personDetails.Email") == '' && intakeView.viewModel.get("personDetails.CellPhone") == '' && intakeView.viewModel.get("personDetails.HomePhone") == '' && intakeView.viewModel.get("personDetails.WorkPhone") == '') {
                    return false;
                }
                else {
                    return true;
                }
            }

        },
    });
    if (!window.data("kendoWindow")) {
        window.kendoWindow({
            width: "600px",
            title: "Valdiation errors",
            visible: false
        });
    };
});

Whenever I debug it blows off and gives me error saying "0x800a138a - JavaScript runtime error: Function expected". I checked multiple times if I am missing any parenthesis but I cannot see anything.

HereToLearn_
  • 1,150
  • 4
  • 26
  • 47
  • How do we reproduce this error ? – Rayon Sep 21 '15 at 17:30
  • @RayonDabre this is happening on page load. I think i might be missing some parenthesis or semicolon. – HereToLearn_ Sep 21 '15 at 17:31
  • 1
    Sounds like you've passed some other type of argument (or not argument at all) instead of a function. Also, in your code `data('kendoValidator')` must return a function. Does it? If it returns an object instead, you've missed the dot and the method name, since an argumentlist follows: `... = $("#Details").kendoValidator().data("kendoValidator")({rules: {...})`. Notice two sequential `()`s here. – Teemu Sep 21 '15 at 17:47

4 Answers4

0

EDIT: found more wrong syntax, you have an unneeded comma & semi-colon:

$(document).ready(function() {
    var window = $("#window");
    viewModel.validator = $("#Details").kendoValidator().data("kendoValidator")({
        rules: {
            checkPersonContactInfo: function (input) {
                if (intakeView.viewModel.get("personDetails.Email") == '' && intakeView.viewModel.get("personDetails.CellPhone") == '' && intakeView.viewModel.get("personDetails.HomePhone") == '' && intakeView.viewModel.get("personDetails.WorkPhone") == '') {
                    return false;
                }
                else {
                    return true;
                }
            }

        } // here there was a comma which was not needed.
    });
    if (!window.data("kendoWindow")) {
        window.kendoWindow({
            width: "600px",
            title: "Valdiation errors",
            visible: false
        });
    } //here you had also a trailing ; which I removed
});
Saar
  • 2,276
  • 1
  • 16
  • 14
  • yes, trailing comma in a javascript object will cause syntax error – Saar Sep 21 '15 at 17:37
  • It will never give you syntax error. Its just not needed there. – Rayon Sep 21 '15 at 17:40
  • If you write it in a good IDE with linter it will give you a syntax error. – Saar Sep 21 '15 at 17:42
  • We can never call them **syntax errors**, this is just a warning which need to ne avoided, but this is not the cause in this case.. – Rayon Sep 21 '15 at 17:45
  • Just saying, a trailing comma will trigger a __parsing time__ syntax error, and only in older IEs. – Teemu Sep 21 '15 at 17:57
  • [They are part of the spec since ES5 and legal in array definitions since ES3.](https://stackoverflow.com/questions/7246618/trailing-commas-in-javascript) – sdgluck Sep 21 '15 at 17:59
0

The trailing comma could be the issue:

 }, 
Michael D
  • 678
  • 3
  • 11
0

like mentioned before the trailing comma is the problem in your code. A trailing comma in JavaScript object literals is valid since the ECMAScript 5 specification and so it is valid in the most modern browser. Nevertheless there are problems with IE and in older browser you get syntax errors.

I just optimized it with the help of WebStorm and this is the output of WebStorm :-) (There was also an unnecessary semicolon in your code):

$(document).ready(function() {
    var window = $("#window");
    var viewModel = {};
    viewModel.validator = $("#Details").kendoValidator().data("kendoValidator")({
        rules: {
            checkPersonContactInfo: function (input) {
                return !(intakeView.viewModel.get("personDetails.Email") == '' && intakeView.viewModel.get("personDetails.CellPhone") == '' && intakeView.viewModel.get("personDetails.HomePhone") == '' && intakeView.viewModel.get("personDetails.WorkPhone") == '');
            }
        }
    });
    if (!window.data("kendoWindow")) {
        window.kendoWindow({
            width: "600px",
            title: "Valdiation errors",
            visible: false
        });
    }
});
Christoph W.
  • 958
  • 2
  • 10
  • 24
0

i think you are trying to do something like this:

viewModel.validator = $("#Details").kendoValidator({//this is the change you need
        rules: {
            checkPersonContactInfo: function (input) {
                if (intakeView.viewModel.get("personDetails.Email") == '' && intakeView.viewModel.get("personDetails.CellPhone") == '' && intakeView.viewModel.get("personDetails.HomePhone") == '' && intakeView.viewModel.get("personDetails.WorkPhone") == '') {
                    return false;
                }
                else {
                    return true;
                }
            }

        },
    });

MORE: see this

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
  • according to the article you shared we should define validator like this: var validator = $("#Details").data("kendoValidator"); – HereToLearn_ Sep 21 '15 at 20:14
  • This part is to add rules to your validator. on your call(save/update) it should trigger the defined validation rules as in the given link he is doing on `save`. – Suchit kumar Sep 22 '15 at 02:58