knockout validation - ko is undefinded

438 views
Skip to first unread message

Israel Lorenz

unread,
Mar 9, 2014, 9:43:31 AM3/9/14
to duran...@googlegroups.com

I'm trying to use knockout validation to validate very simple form, but without success. I'm getting this following erros vevn so I'm calling required :

Uncaught Error: Failed to load routed module (stores). Details: Cannot read property 'ko' of undefined.

store.html


<form data-bind="submit:addMovie" class="form-horizontal" role="form">

<fieldset data-bind="jqValidation: validationContext">
    <div class="form-group">
        <label for="inputName" class="col-sm-2 control-label">Store:</label>
        <div class="col-sm-3">
            <input class="form-control" id="inputName"  placeholder="Store" data-bind="value:title">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-4">
            <button class="btn btn-primary" id="save" value="Add">Sign in</button>  <button type="submit" class="btn btn-default">Cancel</button>
        </div>
    </div>
</fieldset>

store.js

define(function (require) {
var router = require('plugins/router');
var ko = require('knockout');

var title = ko.observable().extend({required:true, message:"bla bla bla"});

var vm = {
    title: title
};
vm["errors"].ko.validation.group(vm);

return vm;

Why ko is undefined?!


John Bertoncelli

unread,
Mar 9, 2014, 10:27:03 AM3/9/14
to duran...@googlegroups.com
Hi,

Did you add ko validation script library to your web page? If I am not wrong ko and ko validation are global scope then both should be available for you to use inside your view and view model.

Israel Lorenz

unread,
Mar 9, 2014, 11:49:24 AM3/9/14
to duran...@googlegroups.com
Hi,

I have this line on my index.html


    <link rel="stylesheet" href="lib/knockout.validation/Dist/knockout.validation.js" />


בתאריך יום ראשון, 9 במרץ 2014 16:27:03 UTC+2, מאת John Bertoncelli:

John Bertoncelli

unread,
Mar 9, 2014, 12:05:38 PM3/9/14
to duran...@googlegroups.com
Is your ko validation script tag inside your index.html page located after the ko library script tag?

Make sure that you have the right setup too. The main.js, shell.js should be used at least to start with for application startup. Then your view model and view must be inside the righ folders. Try simple to start with maybe only one input field. The first view model should be used to define your observable and to expose it to be used by the view. Your observable will be extended inside the view model with the validation rules. Make sure that your ko validation environment is initialized as well inside your view model, there is few statements required to initialize ko-validation. Remember that when inside a view model you have to define KO. KO has been required inside the main.js and or shell.js but each view model must define it too.

Israel Lorenz

unread,
Mar 9, 2014, 12:15:30 PM3/9/14
to duran...@googlegroups.com
my validation is not on my index.html, is on other file. 

בתאריך יום ראשון, 9 במרץ 2014 18:05:38 UTC+2, מאת John Bertoncelli:

Israel Lorenz

unread,
Mar 9, 2014, 12:42:22 PM3/9/14
to duran...@googlegroups.com
the main->shell->store is working.
i can see my form.

just when i'm trying to validate it using knocout i get errors (already 3 days for few lines...)

בתאריך יום ראשון, 9 במרץ 2014 18:15:30 UTC+2, מאת Israel Lorenz:

John Bertoncelli

unread,
Mar 9, 2014, 5:11:39 PM3/9/14
to duran...@googlegroups.com
I shall try to send you a sample tomorrow. Email?

Israel Lorenz

unread,
Mar 10, 2014, 5:13:25 AM3/10/14
to duran...@googlegroups.com
Thanks

my emain is: israel...@gmail.com

בתאריך יום ראשון, 9 במרץ 2014 23:11:39 UTC+2, מאת John Bertoncelli:

John Bertoncelli

unread,
Mar 10, 2014, 7:21:20 AM3/10/14
to duran...@googlegroups.com
Do you have visual studio?
Reply all
Reply to author
Forward
0 new messages