Creating modal dialogs is so hard

Why the documentation on creating modal dialogs is so hard to understand. The example given seem to not take a developer anywere. There is not a clear path about how to do a modal from start to finish afaik. :frowning:

Making an alert is so thoroughly described How to show an alert Ā· Adobe XD Plugin Reference, but Dialogs not.

What I mean is if iā€™m having a command say:

function myCommmand() {
// my code here
}

which code and where exactly do I put it so the dialog (prompt) will fire as soon as I invoke my main commnand?

So, please make it more clear. Thanks!

1 Like

May I ask which aspect is unclear? It is some standard JavaScript stuff (creating the DOM elements you need) and together with the https://adobexdplatform.com/plugin-docs/reference/ui/dialogs/ section, I havenā€™t found anything to be unclear.

For more complete examples, there are the samples available at https://github.com/AdobeXD/plugin-samples, but dialogs come in many ā€œshapesā€ (some more complex, some more minimalistic) and I donā€™t think thereā€™s a ā€œone-for-allā€ solution they could show in the documentation (this ā€“ really ā€“ is the developerā€™s decision how to show the dialog: Do it with React? Create an own helper for that? Somethng completely different :wink:).

The alerts could be easily shown since they use the helper library making it a simple function call, but since dialogs are just standard DOM-Manipulation (with all differences already getting described in the documentation), Iā€™d be interested to know what kind of documentation youā€™d like. For now, https://github.com/AdobeXD/plugin-samples/tree/master/ui-hello is the most minimalistic example for showing a dialog and should help you get startedā€¦

Hope this helps,
Best,
Pablo

1 Like

thanks @pklaschka,

so for example here it gives me the code but I donā€™t know how to invoke it in a real plugin situation, basically the user would not know what to do with it: https://adobexdplatform.com/plugin-docs/reference/ui/dialogs/#js

1 Like

Correct me if Iā€™m wrong, but that can be seen in the samples (and the information that this is just a plain old HTML dialog element that can be invoked by dialog.showModal(), which returns a Promise (see e.g. https://adobexdplatform.com/plugin-docs/reference/ui/dialogs/showing.html), is pretty much all the information one needs). After all, this is a reference, and the samples serve as examples to put those things into a real context.

Since this is meant for people already familiar with HTML, CSS, and JavaScript, Iā€™d argue that thatā€™s all the information someone with that expertise needs (and everything on top of that would ā€“ in my opinion ā€“ clutter up the docs). Donā€™t get me wrong here, Iā€™m not saying that youā€™re wrong (the docs are a bit shallow here), but I would argue (and for the sake of making the docs better like to state this point of view), that thatā€™s the way this should be (providing the info people need, serving examples in the samples and requiring some Frontend-Skills that can be acquired elsewhere so the docs can stay as lean and easy to read as they are) :wink:.

1 Like

@pklaschka Alright, I understand now :slight_smile:
Finally I accomplished what I needed to do, after a very long trials and errors, but still I did not make all the features that the plugin needs to be for a better experience, but I need to familiarize myself more with Promises and async await since I was not accustomed with Dialogs in my website development personal history.

1 Like

There is nothing more fulfilling than the knowledge that one has gotten something to work after trying hard :wink: ā€“ congratulations. Iā€™m glad you got it working.

Happy coding!

2 Likes

@pklaschka is there a way to make a prompt remember last input typed in the box?

Not an easy one, Iā€™m afraid. I did something like this for my plugins, but youā€™ll have to use the file system APIs, create a settings file in the plugin settings folder, store the input when the ā€œApply distanceā€ button gets pressed and retrieve them when you show the modal.

I have some code for that (making it much easier), though. Therefore, if you can wait until tomorrow, I can share this code on GitHub (I wanted to make it open source, anyway, so this is a good excuse for me to take the time to do it :wink:) so it would be much easier and you wouldnā€™t have to reimplement this (more or less cumbersome) system (checking if the settings file already exists etc.) yourself.

Best,
Pablo

2 Likes

I just found out that Frame Maker plugin remembers userā€™s last input. Very cool plugin.
Iā€™ll wait until tomorrow, thanks!
I already tryied your plugins without even knowing. I like them a lot :wink:

1 Like

Hi @pklaschka, @aldobsom, thank you for using Frame Maker.

do you mean remembering inserted data after reloading plugins? usually they already keep inputs unless you reload them.

2 Likes

@pklaschka
for example this code doesnā€™t work like this:

WORKAROUND:
I made it work by having the getDialog() function to only ā€œreturn dialog;ā€ not ā€œreturn dialog.showModal();ā€, and add this at the end:

function menuCommand() {
    //  attach the dialog to the body and show it
    document.body.appendChild(getDialog()).showModal()
    .then(result => {
        // handle dialog result
        // if canceled by ESC, will be "reasonCanceled"
    });    
}

//  this file is deliberately written in low level document.appendChild format.
module.exports = {
    commands: {
        menuCommand
    }
};

https://adobexdplatform.com/plugin-docs/reference/ui/dialogs/dismissal.html
And here it says:

You can listen for the default gesture (typically [ENTER]) by registering for the submit event on the form :

function onsubmit() {
    dialog.close("ok");
}
form.onsubmit = onsubmit;

BUT where to put this code in the code of the dialog?

You would need to get the form element (e.g. assign it an id <form method="dialog" id="myForm">, get a reference to it in your code (document.getElementById('myForm')) and then, you could use this code. Iā€™d also suggest returning a new Promise which you manually resolve when onsubmit() gets called instead of showModal() ā€“ this allows you to get all your code in there (you could ā€“ for example ā€“ resolve this with an object containing options a user has selected and use the result you await elsewhere to do what your plugin should do).

1 Like

@pklaschka Thanks Pablo, apparently Iā€™m too unqualified for this kind of stuff :frowning:
I barely understand how these even work :confused:
I wish there were better example with a more complex scenario.

1 Like

@aldobsom Youā€™ll get the hang of it :wink: . With this part, though, I agree 100% (after looking at it again with this specific question in mind) that the documentation is quite bad (and not very precise) in this area. I remember some earlier version which was much clearer on this (I like bare-bones docs, as stated before, but snippets where its unclear where theyā€™d belong are something different :wink:) .

@kerrishotts I have to agree with @aldobsom that this is more than imprecise ā€“ there are some code snippets where itā€™s unclear where they would belong (actually, they canā€™t be easily incorporated into the very few code examples provided by the docs ā€“ e.g., https://adobexdplatform.com/plugin-docs/reference/ui/dialogs/dismissal.html into https://adobexdplatform.com/plugin-docs/reference/ui/dialogs/#js). It might be wise to give some less bare-bones example code here since itā€™s difficult for new users to understand (more similar to the way it was during the Beta-Docs, showing a ā€œfullā€ example code section including dismissal, creating and showing a dialog)ā€¦

2 Likes

@aldobsom In the meantime, I digged around in the docs repo and looked through the older commits (as I stated: I found the docs on this to have been more comprehensible before and since these commits are publicly available on GitHub, I guess my NDA doesnā€™t apply to that :wink:), and hereā€™s a version from a while back: https://github.com/AdobeXD/plugin-docs/blob/4a75bee64f875e0a0f9b6e09869cd6c33c5c9d80/reference/ui/ui-concepts.md

It might not be up-to-date, but it might help you a bit (itā€™s the ā€œoriginalā€ docs with which I have learned it during the Beta, so itā€™s at least possible to learn it with that :wink:)

Hope this helps,
Happy coding,
Pablo

2 Likes

While Iā€™m still working on the documentation of it, here is a link to the repo of my ā€˜storage helperā€™ (Iā€™m also working on a small example for using it to have default values in inputs): GitHub - pklaschka/xd-storage-helper: A little helper to make storing key-value-pairs (e.g. settings) for Adobe XD plugins easier.

Hope this helps,
Best,
Pablo

2 Likes

Weā€™re working on more docs, so things should improve on that front. I thought there was a complete example in the docs, but took another look and there isnā€™t. Apologies!

That said, the UI is going to be the most difficult piece to build from scratch. There are some helper methods in the Plugin Toolkit repo (https://github.com/AdobeXD/plugin-toolkit) that can simplify some parts of it, and maybe thereā€™s a way we can extend those helper methods to cover some of the more complex bits as well. The setup/teardown aspects can be really tedious and easy to get wrong ā€“ and ultimately they are boilerplate, so there may be ways to simplify with abstraction.

Ideas of course, are welcome. More tutorials are going to get added as well, which should help (the advanced concepts section is more about whatā€™s available, and less about the ā€œhowā€, where as tutorials are intended to show step-by-step how to get something going.)

Anyway ā€“ off to lunch, but planning on doing some writing on the docs today. :slight_smile:

2 Likes

Hi, @kerrishotts, @pklaschka, @aldobsom

any news about keeping input data?
@aldobsom I see you used the template literals syntax.
You may try the document.creatElement() variation, just to see if it will solve.

Sincerly, I donā€™t know if such a change could be the right solution.

@PaoloBiagini

I think I saw something on the docs describing this, but I canā€™t seem to find it anymore :confused:

@kerrishotts I thought there was a complete example in the docs, but took another look and there isnā€™t. Apologies!
By complex I hope you mean ā€œfully explainedā€ example that just works when copypaste :slight_smile:

@pklaschka

I cannot reproduce what you say. I wish there was some code somewhere to read it :slight_smile:

And no matter where I put the code below

 dialog.close(document.getElementById("myForm").value);

or

dialog.close(document.getElementById("myForm"));

always gives me: null or undefined. I dontā€™t know what to do with it :frowning:

source here: https://github.com/AdobeXD/plugin-docs/blob/4a75bee64f875e0a0f9b6e09869cd6c33c5c9d80/reference/ui/ui-concepts.md