Async function prompt

welcome everybody
I have a problem with the following code that can help you solve it.

First: Sorry for not being clear, it was because of the speed. Second: The problem is that I want when the user enters the email address in the field, the promise is fulfilled and he can use the plugin. So I created a code in the form of a prompt response message The problem is that I can’t fulfill the promise. I hope the picture of the code is clear Gratefully.


const r = await prompt("Email put here", "This is correct Email.", ["Cancel", "Email"]);
if ((r||"Email") !== "Email") { /* cancelled or No */ }
else { /* Yes */ }

const r = await prompt("cancelled", "Are you sure you wish to cancelled ? This action cannot be undone.", ["Cancel", {variant: "warning", text: "cancelled"}]);
if ((r !== "cancelled") { /* nope, don't do it! */ }
else { /* Do the cancelled */ }

Regards :pray:
Mohammed Abed.

  1. Please format your code. Currently it’s a mess
  2. What the actual question is here? Are you asking for help? Are you just showing your code?

Can you use prompt() at all in UXP? I believe it’s undefined.

UXP is not a browser and I think it does not exist here.

Hi David
Yes it worked for me but I can’t control the promise
As in the following attached video… see.
my regards
Mohammed Abed.
LOOK !!!

prompt() is not native of UXP, so my understanding from your video recording is that you’re importing/using a construct to fire that very dialog. It’d be helpful to get that bit of code too, in order to assess why it doesn’t work as you expect.

Hi David
Here is the code that I used.
I hope everything is clear now for you to share with me a solution to my problem.

// CODE async function showPrompt:
//👇 The problem is that the promise is not fulfilled.👇
async function showPrompt() {
    const res = await prompt("🧢Please Enter The Email Address Registered  In Your 🧨MF Productions(UXP)🧨 Account And Press OK To Active Your License:", "Shape", ["Cancel", "OK"]);
    switch (res.which) {
        case 0:
            //👇 When the condition or email is not met, this message appears👇
            return alert("🧢Please Restart Photoshope And Enter The Email Address Registered  In Your 🧨MF Productions(UXP)🧨 Account To Active Your License.", "You didn't want to apply a shape.");
        case 1:
            //👇 What I want is when the user enters the email with which he registered on my site, to check if it is correct?? This message appears👇
            return alert("\n🏆Congratulations!!🏆\n MF Productions(UXP)You Deserve🥇\n\nRegards...\n\nMohamed Fathy", `You wanted to create a ${res.value}!`);

//👇 I also created a function when the plugin restarts👇
async function onLoaded() {
    E1[4] = await checkLicense();
    var ABED = showPrompt();
    var Mohammad = e8.i$();
if (!E1[4][e8.i$()]) { licenseChecked = !!({}); if (E1[4][e8.i$()]) { dialogs[showPrompt()](E1[4][showPrompt()]); } } else { dialogs[showPrompt()](E1[4][showPrompt()); }
//👇 But this function is not confirmed checkLicense();

//👇 I hope the idea is clear now
//👇 Please help in providing a solution to my problem
//👇 Regards...
//👇 Mohamed Fathy...

:point_down: Regards…
:point_down: Mohamed Fathy…

It would be better if you use a dialog or sp-dialog element with a text input element that returns the email. This way you have more customization and control over your output and input.

@DavideBarranca has a great tutorial to understand the foundation of this and then you can customize it yourself, the tutorial helped me to understand how it works the promise and so.


I meant the code for the prompt() function, that you call inside showPrompt().
When I try to run prompt(), the Console (PS 24.2) isn’t happy.

Are you running this in Photoshop or XD?

Hi David.
I’m running it on Photoshop version 23.1.0 And I tried it in the private videos that I sent you.
It works but the promise from license verification is not fulfilled .

Greetings :pray:
Mohamed Fathy.

Hi David.
I defined pomprt through the lib folder, I put it inside the plugin folder, where the dialogs.js script is located.
I declared it inside the index.js main plugin script.
for communication between them.

Regards :pray:
Mohamed Fathy.

Can you please share the code for prompt that you have in the lib folder? I’ll help to make sense of it all.

hello photonic.
Thank you, my friend. I see your opinion.
My work is correct, but I want to change the appearance of the interface to the way I put the email. I did that, but my problem is that the promise condition is not fulfilled.
I will look at the video you sent, thank you for your help and I hope you have an idea to help me with it.

Regards :pray:
Mohamed Fathy.

1 Like

Here you Go David !!
The Code:

//👇 CODE async function Prompt👇:
//👇 The dialog.👇
<form method="dialog">
    <h1 class="h1">
        <span ${isError ? `class="color-red"` : ""}>${title}</span>
        ${icon ? `<img ${usingPluginIcon ? `class="plugin-icon" title="${}"` : ''} src="${icon}" />` : ''}
    <hr />
    <div class="container_dialog">
            !render && (
                template ? template() : (
                 //🚀🚀 Mohammad => strToHtml(msg)).join('') + ...🚀🚀
                    (prompt && !promptSlider ? `<label>${
                        multiline ?
                        `<textarea id="prompt" placeholder="${prompt}"></textarea>` :
                        `<sp-textfield id="prompt" placeholder="Enter your E-mail here..Regards" quiet></sp-textfield>`
                    }</label>` : '') +
                    (promptSlider ? `<label>
						<sp-slider id="prompt" show-value="true" style="width:200px;position:relative;top:-10px;" min="0" max="100" step="1" value="80"><sp-label slot="label"></sp-label></sp-slider>
                    </label>` : '')
        ${{label, type, variant} = {}, idx) => `<sp-action-button style="margin-right:10px;" id="btn_${idx}" type="${type}" uxp-variant="${variant}">${label}</sp-action-button>`).join('')}

    // if render fn is passed, we'll call it and attach the DOM tree
    if (render) {

    //🚀🚀  The "ok" and "cancel" button indices. OK buttons are "submit" or "cta" buttons. Cancel buttons are "reset" buttons...🚀🚀 
    let okButtonIdx = -1;
    let cancelButtonIdx = -1;
    let clickedButtonIdx = -1;
//👇 I hope the idea is clear now
//👇 Please help in providing a solution to my problem
//👇 Regards...
//👇 Mohamed Fathy...

:point_down: Regards…
:point_down: Mohamed Fathy…