-1

I am working on Trailhead module "Build the AccountList Component" https://trailhead.salesforce.com/en/projects/slds-lightning-components-workshop/steps/slds-lc-4

When I click on Delete button, it is not showing alert(confirmation) message.

Below is the code - Lightning component-

<form class="account-form" onsubmit="{!c.deleteAccount}">
              <input type="hidden" value="{!account.Name}" class="account-name" />
              <!--
                Use a Lightning Base Component
                To display an icon next to the label
               -->
              <lightning:button label="Delete"
                                iconName="utility:delete"
                                iconPosition="left"
                                variant="destructive"
                                />
            </form>

Controller.js code

({
  doInit: function(component, event, helper) {      
    // Fetch the account list from the Apex controller   
    helper.getAccountList(component);
  },
  deleteAccount: function(component, event, helper) {
    // Prevent the form from getting submitted
    event.preventDefault();
    // Get the value from the field that's in the form
    var accountName = event.target.getElementsByClassName('account-name')[0].value;
    confirm('Delete the ' + accountName + ' account? (don’t worry, this won’t actually work!)');
  }
})
  • 1
    Can you be more specific? What do you mean "nothing is happening"? Also, this code is specifically designed not to delete records. – sfdcfox Apr 4 '18 at 11:43
  • On click of button, it should show an alert.. but it's not – Rohit Patil Apr 4 '18 at 11:51
0

There is slight mistake in the code sample in Trailhead module. I had to add new attribute type="submit" in lightning button as shown below to make it work-

<lightning:button label="Delete"
                                iconName="utility:delete"
                                iconPosition="left"
                                variant="destructive"
                                **type="submit"**
                                />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.