I am creating my first power-up for Trello, and I’ve run into a bit of a roadblock. The purpose of the power-up is very simple - to expose the state of all checklists on the back of a card in the form of a progress bar on the front of the card (using card-badges).
It very almost works, but not quite… When I load the board, all cards show the string “N/A”, which is the fallback string when no checklist items are detected. The cards obviously have checklists though, as the in-built checklist card-badge works just fine, showing (3/7, or 2/14, or whatever the case may be). However, the moment I check or uncheck any item in a checklist, the progress bar appears on the front as expected.
My guess is that the .initialize method is being called before the cards are fully loaded, or something along those lines. As a first-timer here, I expect I am probably just missing something extremely obvious… Can anyone point me in the right direction?
I’ve delved a bit deeper now, and discovered that the actual breaking point is where I try to access “checklist.checkItems.length” for the first time. I’m finding that until the state of a checklist item changes at least once, I get this error:
“TypeError: Cannot read properties of undefined (reading ‘length’)”
The moment I change the state of any checklist item though, the property becomes “defined”, and thus, “readable”. Does anyone know how I could define/read it from the get go? Is there perhaps another way to access checklist properties I just don’t know about?