Play Games

Search This Blog

Saturday, May 21, 2022

display Confirm dialog box in Lightning Web Component(LWC) - SalesforceGlobe4U

display Confirm dialog box in Lightning Web Component(LWC) - SalesforceGlobe4U

Solution: Use LightningConfirm module to show confirm box in lightning web component.

Example:

showConfirmBoxInLWC.html

<template>

    <lightning-card>

        <lightning-button label="Show Confirm Dialog" onclick={showConfirm}></lightning-button>

    </lightning-card>

</template>

showConfirmBoxInLWC.js

import { LightningElement } from 'lwc';

import LightningConfirm from 'lightning/confirm';

export default class ShowConfirmBoxInLWC extends LightningElement {

    async showConfirm() {

        await LightningConfirm.open({

            message:'Are you ready to learn Lightning Confirm Box in LWC?',

            label:'Welcome to Lightning Confirm'

        }).then((result) => {

            console.log('confirm: ',result);

        });

    }

}

showConfirmBoxInLWC.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>54.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:





No comments:

Post a Comment