Hi there,
I would like to do this with code, rather than set the values in a form with hidden fields. As there seems no way to set a default value for a number field, e.g. 0, I would like some code to check if the field is empty, then set the value to 0. As this is a number field, == "is not working and I can’t check for a value with < or >.
Ideally…
if isNULL(item.numberfield) {
item.numberfield = 0
}
Your help is appreciated.
Thank you,
Kyle
import wixData from 'wix-data';
const DATABASE = "Your_DB_ID_HERE";
const DATAFIELD = "Your_DATAFIELD_ID_HERE";
$w.onReady(()=>{
$w('#myButton').onClick(()=>{
checkDB4emptyFields();
});
});
function checkDB4emptyFields() {
wixData.query(DATABASE)
.find()
.then((results)=>{
if(results.items>0) {
let items = results.items
if (items[0].DATAFIELD) {console.log("1-Row-Check-NOT-OK");}
if (items[1].DATAFIELD) {console.log("2-Row-Check-NOT-OK");}
if (items[2].DATAFIELD) {console.log("3-Row-Check-NOT-OK");}
// Put in a LOOP here ---> continue....
}
else {console.log("No DATA found!")}
});
}
Good luck!
@russian-dima thank you!!!