data-control-class="Dropdown" API questions

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

heribertolugo
Posts: 9
Joined: Sun Sep 18, 2022 10:51 pm

data-control-class="Dropdown" API questions

Post by heribertolugo »

I'm having trouble using the dropdown. I see a property called dataSource, in which ive seen used throughout MM files. I looked through the dropdown source and noticed it can only be set to be a list of string, or object (in which the toString method is called on). so my questions/issues are as follows:
  1. Can i add items and specify a value member and a text member? so that the dropdown will display one thing, but each items actual value is something else?
  2. i have tried to set the datasource to an array of string and then a StringList, but doing so in either way causes an exception of "addEventListener function not found! Event focuschange". what am i doing wrong?
  3. i also tried to instead add items using

    Code: Select all

    mydropdown.controlClass.addValue
    , but i still get the same exception as above. i should probably note now that the params are set

    Code: Select all

    data-init-params="{readOnly: true, preload: true}"
    as indicated required by the API. i also tried to attach a function to focuschange

    Code: Select all

    mydropdown.controlClass.localListen(mydropdown, 'focuschange', myFunc);
    event to see if that fixes the issue (even though i didnt see that done in MM files), and that did not change anything.
  4. speaking of params, where are these defined or outlined? i saw a dropdown with

    Code: Select all

    data-init-params="{readOnly: true, dbFunc:'getStringList', dbFuncParams: {category: 'PlayNowActions', includeDefault: true}, preload: true}"
    (pnl_PlaybackRules), but i could not find a reference to any of those params anywhere in the code. i looked in dropdown source, control source and pnl_PlaybackRules.js. how do i know what params are available, as they are not mentioned in the API?
  5. are custom params possible? if so, how would i access them in code?

    basically i am trying to populate the dropdown through code, instead of html. and i would like to know more info about the params. i did find a handful or params in source such as resizable and hasSplitters, but really wish they would be mentioned in the API.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: data-control-class="Dropdown" API questions

Post by drakinite »

1. Unfortunately no. If you do wish to do something like that, a bit of an over-engineered solution would be to write functions to encode/decode the text/value like I did on the 3D Album View configuration script: https://github.com/ventismedia/mediamon ... /config.js
2. Looks like the documentation for Dropdown is a bit lacking. The two easiest ways of setting a dropdown's data source are:
a. adding <option>(myValue)</option> HTML tags inside of the dropdown element in your HTML
b. setting with the "items" attribute, which I've now written documentation for and it'll be up in a bit: (provide a single string as a comma-separated list)

Code: Select all

mydropdown.controlClass.items = 'item1,item2,item3'; // automatically creates newStringList() and adds 'item1', 'item2', and 'item3' to the dataSource
3. The dropdown class expects a native StringList object for its dataSource: https://www.mediamonkey.com/docs/api/cl ... gList.html - I've updated the documentation for dataSource to mention that it expects a StringList.
4. data-init-params are not currently defined or outlined. When a control is initialized (window.initializeControl, mminit.js line ~2140) it reads the data-init-params and passes them as an object to the control's initialize function. It happens that the Dropdown class loops through the params object and assigns each item to itself (dropdown.js line 184). So you could set data-init-params="{foo: 'bar'}", and then mydropdown.controlClass.foo will be "bar".
5. Hopefully my response in #2 and #4 answers that question
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
heribertolugo
Posts: 9
Joined: Sun Sep 18, 2022 10:51 pm

Re: data-control-class="Dropdown" API questions

Post by heribertolugo »

ahh i see...

i went back and tried the StringList again.. seems i had a typo, thats why that wouldnt work. i am able to populate it now using the StringList.

i dont think you mentioned the mydropdown.controlClass.addValue method.. when i remove the preload param, it requests it. when i add the preload param i get the error for the focuschange event. just curious.
Post Reply