Remove Extenders from in Knockout Observable (Knockout Validation)
I have a Knockout view model which is utilizing Knockout Validation for performing validation of the vm properties. I'm trying to change the "max" validator value from within a particular subscriber function. Here is my attempt which I'll follow with an explanation of the behavior I'm seeing.
me.inventoryToPick().key.subscribe(function () {
if (!me.inventoryToPick().key()) {
me.inventoryToPick().location = null;
return;
}
var item = ko.utils.arrayFirst(inventory, function(inv) {
return inv.InventoryKey === me.inventoryToPick().key();
});
me.inventoryToPick().quantity = ko.observable().extend({ max: item.QuantityAvailable });
});
Notice that the observable property to which I'm attempting to attach validation (quantity) is a property of parent observable object (inventoryToPick). Now, the behavior that I'm seeing is that the validation rule is being added to the property, however, it appears that the lowest value wins. In other words, if the max value rule is set to 30 on the first pass and then 10 on the next, validation will be properly enforced on both passes. However, if on the next pass, I attempt to set the max value rule back to 30 (or any value greater than 10), the max value of 10 continues to be enforced.
I thought I might be able to side step this bug by setting my property with a new ko.observable object initialized with the proper max value validation but that didn't solve the problem. Does anyone know of a way to remove the extenders for an augmented knockout observable? Any other suggestions?
Thanks, Vinney
链接地址: http://www.djcxy.com/p/50140.html