问题
I'm trying to get Knockout Validation running on my Breeze.js entities but not having much luck.
So currently I'm just trying to get a very basic test working to confirm the approach should work but am stumped as to why this is not even working. Essentially I have something like the following running when the user edits one of my entities in an attempt to register knockout validation on the resulting entity from breeze:
dataService.getEntity(selectedRowId())
.then(function(result) {
currentEntity(result.entity);
var ent = currentEntity();
ent.TestField.extend({ required: true });
});
And then in the view the field is bound:
<input type="text" data-bind="value: currentEntity().TestField" />
But this is not working. I thought it might be because all the fields on the entity are dependantObservables, but created a test computed field and knockout validation seems to work fine on it (provided I give it a read and write method)
Can anybody suggest what I might be missing or a better way to do this sort of thing?
(PS: I'm actually attempting something like the approach from Julián Yuste here:
knockout validation using breeze utility?
but not having much luck so I'm trying to take it back to some basics)
回答1:
You can get a better and updated example here:
Mark fields not valid as red with knockout/durandal
Take a look and tell me if that helps.
来源:https://stackoverflow.com/questions/15736056/knockout-validation-on-breeze-js-entities