Hey, folks. I’m working on my first serious Meteor project, and I’m running into a bit of an issue.
I’ve got a small page here that contains a table of Categories, and I am using editable-text to allow for edit-in-place functionality for a couple of the fields. Editing seems to work, but to handle some verification, I’ve written/attached a callback to handle the beforeUpdate
callback on the limit
field for my document.
The callback seems to be…well…called back, but it’s not having the effect on my data that I believe it should have. Basically, if a user types in a value of something like 43
, I want this callback to force the value to 43.00
(two decimal places mandatory).
This code segment contains the callback itself:
EditableText.registerCallbacks({
// Callback for editing category limit/budget.
budgetCurrency: function(doc) {
// Variables based on editing.
var oldVal = this.oldValue;
var newVal = this.newValue;
// Verification:
if (isNaN(newVal)) {
// Reject value if not a number, don't make change.
oldVal;
} else {
newVal = Number(newVal);
console.log(newVal.toFixed(2));
return _.extend(doc, {limit: newVal.toFixed(2)});
}
}
});
I’m not sure if I’m doing something wrong or not. The value that is returned via console.log()
is just as I would expect it to be, however the same value (in code) is not what ends up being stored in the updated document.
Any assistance would be greatly appreciated. I could just be overlooking something as far as how beforeUpdate
works (callback), for all I know.
Documentation for the package in question is located at: https://atmospherejs.com/babrahams/editable-text