top of page

Forum Posts

NH
Sep 17, 2018
In Coding with Velo
Hello, I am new to wix coding and pretty lost with a rather basic problem: After user input of a number, I calculated different numbers from the input number using a hook (afterQuery). All numbers (input + calculated) are stored in the same database. Now I wanted to display one of the calculated numbers of the first item of that database. I used all functions from this wix article: https://support.wix.com/en/article/how-to-display-calculated-data-from-a-collection my afterQuery hook (save in a data.js file) looks like this: export function Rate_afterQuery(item, context) { //TODO: write your code here... item.rateBasic = 0.01 item.ratePremium = 0.02 item.priceBasic = item.wordNumber * item.rateBasic; item.pricePremium = item.wordNumber * item.ratePremium; return item; } and my onReady function looks like this: $w.onReady(function () { $w("#dataset1").onReady(() => { populateCalculatedFields(); } ); } ); function populateCalculatedFields() { const currentItem = $w("#dataset1").getCurrentItem(); $w("#text40").text = currentItem.priceBasic; } In the preview, I receive the following error message: Wix code SDK Warning: The text parameter of "text40" that is passed to the text method cannot be set to null or undefined. The afterQuery hook seems to work, as all values in the database are calculated correctly. When I change the last line in the populateCalculatedFields function to the following one, the error above disappears and the word "hallo" is displayed in the respective text field. $w("#text40").text = "hallo" ..so there is definitely a problem with the field type, could it be solved by converting the variable "currentItem.priceBasic" into a string? How would I do this correctly? How would I assign this string correctly to $w("#text40").text? Is there maybe a completely different problem? Thank you so much for your help, I am fighting for a long time with this probably simple problem.... NH
0
5
1k

NH

More actions
bottom of page