Created
September 21, 2020 10:18
-
-
Save Naveendhanaraj/45c9ffbcd5e849f37636f0f8de6f7fa8 to your computer and use it in GitHub Desktop.
Lightning Record Edit Form js file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement } from 'lwc'; | |
import { NavigationMixin } from 'lightning/navigation'; | |
import { ShowToastEvent } from 'lightning/platformShowToastEvent'; | |
export default class LightningRecordEditForm extends NavigationMixin (LightningElement) { | |
redirect = true; | |
resetpage = false; | |
handleSuccess(event) { | |
const even = new ShowToastEvent({ | |
title: 'Success!', | |
message: 'Record created!', | |
variant: 'success' | |
}); | |
this.dispatchEvent(even); | |
if(this.redirect == true){ | |
console.log('handleSuccess'+this.redirect); | |
let creditnoteId = event.detail.id; | |
this[NavigationMixin.Navigate]({ | |
type: 'standard__recordPage', | |
attributes: { | |
recordId:creditnoteId, | |
objectApiName:'Account', | |
actionName:'view' | |
} | |
}) | |
} | |
if(this.resetpage== true){ | |
this.handleReset(); | |
} | |
} | |
handleError(event){ | |
const evt = new ShowToastEvent({ | |
title: 'Error!', | |
message: event.detail.detail, | |
variant: 'error', | |
mode:'dismissable' | |
}); | |
this.dispatchEvent(evt); | |
} | |
saveAndNewClick() { | |
this.redirect = false; | |
this.template.querySelector('lightning-record-edit-form').submit(this.fields); | |
this.resetpage = true; | |
} | |
handleReset() { | |
const inputFields = this.template.querySelectorAll( | |
'lightning-input-field' | |
); | |
if (inputFields) { | |
inputFields.forEach(field => { | |
field.reset(); | |
}); | |
} | |
} | |
handleCancel(event){ | |
var url = window.location.href; | |
var value = url.substr(0,url.lastIndexOf('/') + 1); | |
window.history.back(); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment