简体   繁体   中英

knockout.js validation plugin not working with CakePHP

I'm trying to use the knockout.js validation plugin with CakePHP but I can't seem to get it working.

I'm including the validation plugin at the end of the corresponding view. The network tab in Chrome shows it loading properly, however, any reference to the validation plugin throws an error.

For example, on my page that contains my viewmodel(named EntryViewModel), I have the following code

function EntryViewModel(){
  //viewmodel code here
}

EntryViewModel.errors = ko.validation.group(EntryViewModel);

Here is the error

'Uncaught type error: cannot call method 'group' of type undefined'

Am I referencing it incorrectly? At the end of my CakePHP view I include the knockout.validation file and it shows properly loaded in the network tab

EntryViewModel is trying to use knockout validations, but it hasn't been loaded at that point in the execution order. You can't use a library before it's loaded, so make sure the order is correct. Example:

<script src="knockout.js"></script>
<script src="knockout.validations.js"></script>
<script src="orders.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM