List and choose Calendar names in prompter

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk List and choose Calendar names in prompter

Viewing 4 reply threads
  • Author
    Posts
  • March 12, 2021 at 1:37 AM #43808

    Chris Ju
    Participant

    Hi,

    i’m using the new JS API function Utils.getCalendarNames() (Big thanks to Brendan for this!) in the prompter dialog to list/choose and use for my scripts:

    ...
    arr = Utils.getCalendarNames();
    var calname;
    let prompter = Prompter.new();
    prompter.addParameter('Kalender: ', 'calname', 'popup', [arr[0], arr[1], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8], arr[9], arr[10], arr[11], arr[12], arr[13], arr[14], arr[15], arr[16], arr[17], arr[18], arr[19], arr[20], arr[21], arr[22], arr[23], arr[24], arr[25], arr[26], arr[27], arr[28], arr[29], arr[30]])
    .show('Bitte Kalender auswählen:', callbackFunction);
    ...

    1. In my case i have 30 items from the array in my list. If i have less than 30 calendars, the “missing” items in the prompter are empty. Is it possible to limit the list according to the length of the array so that only the calendars that actually exist are displayed?

    2. Is it possible to sort the calendar list alphabetically?

    Thanks!

    Chris

    March 12, 2021 at 8:50 PM #43812

    Sam Moffatt
    Participant

    Why don’t you just do the following:

    prompter.addParameter('Kalender: ', 'calname', 'popup', arr)
             .show('Bitte Kalender auswählen:', callbackFunction);
    

    And sorting should just be arr.sort() instead of just arr:

    prompter.addParameter('Kalender: ', 'calname', 'popup', arr.sort())
             .show('Bitte Kalender auswählen:', callbackFunction);
    

    Since arr is already an array, you don’t need to extract it back out to be an array.

    One other trick is the JavaScript spread operator which will expand out an array for you automatically though in this case it’s not useful (since you’re expanding an array back into the same array):

    prompter.addParameter('Kalender: ', 'calname', 'popup', [...arr])
             .show('Bitte Kalender auswählen:', callbackFunction);
    

    You can also do a [...arr].sort() as well because the [] syntax is returning an array object you can operate on directly.

    It’s possible I miss understood something but I think this solves the problem for you.

    March 13, 2021 at 12:02 AM #43817

    Chris Ju
    Participant

    Oh my goodness, so simple. I definitely have to take a programming course.

    Thank you very much, Sam!

    March 13, 2021 at 5:22 PM #43826

    Sam Moffatt
    Participant

    There is a bunch of Javascript resources out there, mostly focused on the web unfortunately but the basics of the language are transferable so it’s not a complete waste, plus it helps understand how the web works as well so not a complete loss. Javascript is an awkward language at times with a bunch of beginner pitfalls but it’s one of the most popular languages out there when you realise every website is powered by it, it’s used as a scripting engine in a bunch of places like Tap Forms and then you have node.js for running it as a server language.

    In any case you’ve got your own use cases with Tap Forms which I feel is the best way to learn. Have a problem you care about that you want to solve and search for how to solve it. It’s a great way to learn how to program :)

    March 14, 2021 at 1:45 AM #43833

    Chris Ju
    Participant

    ;-) … Since i began coding with JS in TF (greatest App ever :)), I’ve been puzzling my code from snippets of the web and this forum, but there are natural limits for a beginner :-/. But I agree with you that there is no better way to learn to code … Thanks again for your great posts in this forum!

Viewing 4 reply threads

You must be logged in to reply to this topic.