Please, I need your help.
I would like to use an “Text Input” ( #input1) to input a number into Collection ( “Tarif” ) but it doesn’t work. The value is null or it’s a string.
It’s ok when I use a “Text Box” but not with “Text Input”.
export function button1_click(event) {
let user = wixUsers.currentUser;
let userId = [user.id;](user.id;
let)
[let](user.id;
let) inValue = parseFloat($w( ‘#input1’ ).value, 2);
wixData.query( “Tarif” )
.eq( “_id” ,userId)
.find()
.then( (results) => {
//console.log(results.items[0]);
let toSave = {
“prix_mois” : inValue
};
//console.log (inValue);
wixData.save( “Tarif” , toSave)
// //wixData.update(“Tarif”, toSave);
});
}
Thx for your help !
Hi,
Try changing the text input type to Number, or just change its value to number, and use wixData.update() instead.
Force the value to be a number:
let value = Number($w('#input1').value);
if (typeof value === 'number') {
inValue = value
} else {
console.warn('The value is not type of number')
}
update the fields inside the query:
wixData.query("Tarif").eq("_id",userId).find()
.then(async(results) => {
if (result.items.length > 0) {
let item = result.items[0];
item["prix_mois"] = inValue;
await wixData.update("Tarif", item).then(()=> {
console.log('The item was saved!')
}).catch((err) => {
console.error('The update process failed!')
console.error(err);
})
} else {
console.warn("Search didn't find any match");
}
}).catch((err) => {
console.error('The search process failed!')
console.error(err);
})
Hope that helped~!
Ahmad
Hello jga2210,
yes it’s a known little problem, also to me.
But there is a simple way to solve this problem.
Look:
You have a DATABASE witch is full of data. Every row has another TYPE right?
- String
- IMAGE
- Boolean
- NUMBER and so on…
Your problem is taht you want compare or set NUMBER with STRING, but a number is not a string! You can count with numbers with strings you can’t.
EXAMPLE: (NUMBER) ----> 1+2 =3
EXAMPLE: STRING ---------> “1”+“2” = ??? ----> RIGHT —> “12”
Well, so how to handle it now?
You can convert NUMBERs into STRINGs, or do it vice versa and convert STRINGs into NUMBERs before handle your futher actions.
Convert STRING to NUMBER:
let myNumber = Number("33") ---> 33 (no STRING anymore)
Convert NUMBER to STRING:
let myString=(33).toString()
How to check which type it is?
console.log(typeof myString) ---> should be "String"
console.log(typeof myNumber) ----> should be "Number"
So, now you should know everything useful, to solve your problem.
Yes I’ve the same conclusion 
But I don’t understand.
Inputbox is type NUMBER
Cell in database is type NUMBER
typeof is NUMBER
but finally the value was inserted = 0
Thanks You Ahmad,
It’s better but not yet good 
Console.Log → ( ‘The item was saved!’)
but the value has been inserted is 0.
I think I’ve a problem with let inValue and let value ?
export function button1_click(event) {
let user = wixUsers.currentUser;
let userId = user.id;
let inValue;
let value = Number($w( ‘#input1’ ).value);
if ( typeof value === ‘number’ ) {
inValue = value
//value is a number but = 0
} else {
console.warn( ‘The value is not type of number’ )
}
wixData.query( “Tarif_abo” ).eq( “userId” ,userId).find()
.then( async (results) => {
if (results.items.length > 0 ) {
let item = results.items[ 0 ];
item[ “prix_mois” ] = inValue;
await wixData.update( “Tarif_abo” , item).then(()=> {
console.log(‘The item was saved!’)
}). catch ((err) => {
console.error( ‘The update process failed!’ )
console.error(err);
})
} else {
console.warn( “Search didn’t find any match” );
}
}). catch ((err) => {
console.error( ‘The search process failed!’ )
console.error(err);
})
}
Hello jga2210,
could you solve your problem here?
No 
I don’t understand where is the problem
Ok, i will check tomorrow.
Ok, you had an issue with the correct input of NUMBERS into database, right?
I just tried to make an example, it’s finaly not completed, but should you demonstrate that it works, take a look here…
https://russian-dima.wixsite.com/meinewebsite/blank
function myFunktion (parameter) {
var inValue
let user = wixUsers.currentUser;
console.log(user)
let userId = user.id;
console.log(userId)
inValue = Number(parseFloat($w('#input2').value, 2));
console.log(inValue)
let toSave = {"prix_mois": inValue};
wixData.save("Tarif", toSave)
.then( (results) => {
let item = results; //see item below
} )
}
Your reference-column has to be set to NUMBER.
I used a STRING-input-field. (In this example INPUT-2).