Hi,
This is the algorithm:
once page loads
check if dataset1 field1 IsNot Null
make Button1 appear
else
keep Button1 hidden/make it disappear/print a message
The logic is to have a download button appear IFF the connected dataset's field has indeed something to download and it's not empty.
So how could I achieve something like this in Corvid/Javascript and more importantly, where would you be kind enough to redirect me for some solid and reputable/tested tutorials?
Thanks in advance!
Looks like you figured out the syntax for If statement but still need syntax to check if a specific field is empty.
Do not rely on text on the page. Check the dataset instead.
Assuming you are checking a dynamic dataset / page with a single item, it will look something like this:
let current = $w("#myDynamicDataset").getCurrentItem.fieldkey();
The field key being the column from your database collection.
You can read Wixs doc to learn more: https://www.wix.com/corvid/reference/wix-dataset/dataset/getcurrentitem
Did you already have seen the example?
Already have tested and tried it out?
Is this example similar to what you want to create?
1) Fill out (download-name) + (url) + (press "Add Download").
2) Do the same again, but do not fill out the URL.
Did you see the difference?
3) Press on one of the DELETE-Buttons.......
The DOWNLOAD-BUTTON itself is still not activated ---> without function in this example.
Also a DATASET is used in this example ! ! !
import wixData from 'wix-data'; $w.onReady(function () { xxx() $w('#dataset8').onReady(()=>{ $w('#button1').onClick(()=>{console-console.log("Saving-Process started"); let toSave toSave = { "title": $w('#input1').value, "url": $w('#input2').value, }; wixData.save("downloads", toSave) .then( (results) => { let item = results; //see item below $w('#dataset8').refresh() console.log("Total-Count = " + $w('#dataset8').getTotalCount()) } ) .catch( (err) => { let errorMsg = err; } ); xxx() }) $w("#repeater1").onItemReady(async($item, itemData, index) => { $item('#button3').onClick(async(event) => { console.log(index); console.log(itemData); // $item("#text1").text = "deleting in process" $item("#button2").hide() await $w('#dataset8').setCurrentItemIndex(index) $w('#dataset8').setFieldValues({ "title": "data deleted", "url": "" } ); //$w('#dataset8').setFieldValue("url", "") $w('#dataset8').save() }) }); }) }) function xxx (parameter) { $w('#repeater1').onItemReady(($item, itemData, index) => { const thereIsNoUrl = !itemData.url console.log(index) console.log(itemData) if (thereIsNoUrl) {$item('#button2').collapse()} }) }
my used dataset = "dataset8"
my used repeater = "repeater1"
field: ---> title = "download-name"
field: ---> url = "Download-URL"
Perhaps you could use-->
function getCurrentItem(): Object
getCurrentItem Parameters This function does not take any parameters. Returns The current item, or null if there is no current item.
once page loads =
$w.onReady() });
Hide or show a button....
$w("#myButton").show(); $w("#myButton").hide();
If-else-logical.....
if( $w("#myElement").hidden) {$w("#myElement").show();} else {$w("#myElement").hide();}
Print a message..... (this message will be shown in the CONSOLE --> Press F12, when you are using google-chrome-browser) also you will find the message in the console of "Preview-Mode").
console.log("YourMessage")
Working with DATASET....
https://www.wix.com/corvid/reference/wix-dataset/dataset
https://www.wix.com/corvid/reference/api-overview/introduction
https://russian-dima.wixsite.com/meinewebsite