Velo: Textbox does not display numbers

Not sure if anyone had a similar issue, but I have a textbox in which I want to show data from an external connection. With below code, it just works fine to display colums which have a field type “Text”. But it doesn’t work with colums which have a field type “Number”.

So if I use $w(‘#text18’).text= results.items[0].description (text field), the data is shown smoothly in my textbox; But when I use $w(‘#text18’).text= results.items[0].duration (number field), nothing is shown. I looked up in the litterary but couldn’t find anything which would help me further. Any support is highly appreciated!

import wixData from ‘wix-data’;

export function externalQuery() {
let inputdata= $w(‘#input1’).value
wixData.query(“Hotel/bookings”)
.eq(“product_code”, inputdata)
.find()
.then((results) => {
console.log(results.items[0]);
$w(‘#text18’).text= results.items[0].duration

A —> NUMBER is NOT a → STRING !!!

And a → STRING is NOT a → NUMBER !!!

Your textfield expects a → STRING, that means all what is STRING → will work and all what is NUMBER won’t work.

How to resolve the issue ?

Well you need some kind of → CONVERSION <—

let myString = (myNumber).toString();
let myString = String(myNumber) ;

So here you can see two different methods of how to CONVERT your NUMBER into a STRING !

@CODE-NINJA: Many thanks for your fast answer, that was exactely the issue :slight_smile:

1 Like

Don’t forget to like it, if you really liked it.
Problem resolved? → mark as → RESOLVED.

You can also use .toLocaleString() if you want the number formatted. For example 1000 vs 1,000.

1 Like