button enabled/disabled while linked to document field in database

I have a database on my site, and it includes a field of “document” type… not all the cells values are filled.
On my site page, I have a repeater with a button.

how I can let each button for each row be enabled if there is a document in that field and disabled if the field cell is empty?

I tried online methods but I think the javascript code was old and does not suit the new Velo code!

Hi there :wave:t2: I do something similar on my site. Below is the working code that I use to accomplish this, just swap out the element IDs for your own and change “yourFieldKey” to the field key of the database item you want to find.

$w.onReady(function () {
    $w("#yourRepeater").onItemReady(($item, itemData) => {
            if (itemData.yourFieldKey) {
            // If there IS a value in the database field 
            $item("#yourButton").enable();
        } else {
        // If there is NOT a value in the database field 
            $item("#yourButton").disable();
        }
    });
});

There are many many forum posts that deal with this exact question, you can check out a few of them here:

:neutral_face: