1

I implemented the Modal Prompt in my LWC https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_dialog_prompt

The documentation does not explain how to grab the user input message when they click "Ok" button.

enter image description here

1 Answer 1

3

I think the documentation is quite clear, check the JS part on how to get the response, you can use the async-await variant of it like this:

HTML

<template>
    <lightning-button onclick={handlePromptClick} label="Open Prompt Modal">
    </lightning-button>
</template>

JS

import { LightningElement } from 'lwc';
import LightningPrompt from 'lightning/prompt';

export default class PromptExample extends LightningElement {
    async handlePromptClick() {
        const response = await LightningPrompt.open({
            label: 'Please Respond!',
            message: 'This is the prompt message.',
            defaultValue: 'Optional initial input value',
        });
        console.log(response);
    }

}
  • When user clicks on cancel button, the response will be null
  • When user clicks on ok button, response will be the value in the input field

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .