Hello there,
I was trying to retrieve a Boolean value from my database, which I'm sure it's true, but the the code that depends on its value doesn't work, and when logging the result the the console it returns false.
let item = $w('#dataset1').getCurrentItem();
let appealed = item.rejected // which is a Boolean value [true]
if (appealed === true) {
$w('#appeal').disable().then(() => { // the code doesn't run here
$w('#appeal').label = "Appealed";
})
} else {
console.log("User hasn't appealed yet") // but runs here
}
While the value in the database is true, I got false whenever I log the value to the console. And I get the message: "User hasn't appealed yet".
Why is this happening!!
Any help will be appreciated.
@anthonyb - I think I know what the problem is, when you make some changes on a particular page, especially the code, and then hit the preview page, the preview content is actually the content cached on the browser, and the changes doesn't take effect on the preview immediately.
To see the latest update when previewing the site, while you're previewing, go to any page, and then go back to the page that you're editing, the latest changes will appear.
Another thing that I noticed, with Boolean fields, when adding an entry to the database, the Boolean value is not checked, and thus should be false, I mean looking at the database, the checked fields makes an impression that the field is true, and the empty (unchecked) field give an impression that the field value is false, but they're not, their value is undefined.
And that make sense, since there's a lot of cases that you want to check whether the field has been modified or not, if it hasn't, the value should be undefined, and after the field is modified, only returns true or false.
I know that you're aware of that since you're one of Corvid masters, but others visiting this thread might benefit from it, also it's a chance for me to make sure if my observations were true or false.
Depending on server response, it is going to sometimes behave the way you originally reported until you put the database onReady on it like follows:
$w.onReady( async function () { $w('#dataset1').onReady(() => { checkIfAppealed(); }) });
Hi Ahmad,
You need to make sure that the page and dataset are loaded before this code executes:
$w.onReady(function () { $w('#dataset1').onReady(() => { let item = $w('#dataset1').getCurrentItem(); let appealed = item.rejected if (appealed === true) { $w('#appeal').disable().then(() => { $w('#appeal').label = "Appealed"; }) } else { console.log("User hasn't appealed yet") } }) });