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>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?!
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.
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.