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.
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.
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 benull
- When user clicks on
ok button
, response will be the value in the input field