This issue I had great difficulty with hence this post.
The idear:
An user inputs some number and this input is used in a simple multiplying function, by clicking a button. The backend function looks like the following:
The two input fields are labeled #input1 and #input2, this is the standard name then creating them.
The text fields is labeled #text1 also a standard name.
export function multiply(factor1, factor2) {
let product = factor1 * factor2;
return product;
}
Simply taking factor1 and multiplying it with factor2. The frontend looks like this:
import {multiply} from ‘backend/SimpleTestFunc’;
export function button1_click(event) {
multiply($w(“#input1”).value,$w(“#input2”).value)
.then(product => {
console.log(product)
product = product.toString();
$w(“#text1”).text = product
})
. catch (error => {
console.log(error);
});
}
The event of button 1 is a click. (The first line in the frontend code).
Note here that the console.log(product) is not necessary for the code to work, though it is nice to see the output in the case that something happens to the textbox.
A textbox contains a string, this is why the “product = product.toString();” is in the code, the textbox can’t contain a number. This turns the result of the backend function called “product” into a string.
$w is necessary for the code to access the fields: the textbox, the user input… After the call of each input a “.value” is there because the code must know that kind of input it can expect. In our case a number. The same goes fore the textbox. It’s text we enter into the textbox.
I hope this helped.