+ Start a Discussion
diwakar rajputdiwakar rajput 

can i save the record of a form using another component button click

i have a modal in lightning. In this Modal i have a header , body and fotter . In body i am using a component for input data form and In footer I am using another component for save button. now I want to save record onclick of footer button.can i do this?

please help me

Thanks 
Leo10Leo10
Hi,
It is possible, but you need to use Lightning Event.

Thanks,
Nabeel KT
Ashwin Kumar SrinivasanAshwin Kumar Srinivasan
Hi,
You can achieve this by referencing the controller method of the body to the footer button onclick, assuming if you are using lightning:overlayLibrary (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_lightning_overlayLibrary.htm) once you have created the body component dynamically from the place you creating the modal and if its reference is bodyComp  then you can do something similar to what has shown below. You get can get the reference of the controller method named "saveMyrecord" and bind it with footer action.
$A.createComponents([
							["lightning:button", {
								label: 'Cancel',
								onclick: bodyComp.getReference("c.cancel")
							}],
							["lightning:button", {
								label: 'Save',
								variant: "brand",
								onclick: bodyComp.getReference("c.saveMyrecord")
							}]
						],
						function (components, status) {
							if (status === "SUCCESS") {
								component.find("overlayLib").showCustomModal({
									header: 'Create Record',
									body: bodyComp,
									footer: components,
									showCloseButton: true
								});
							} 
						});
If you are using something else for your modal you can still use the same principle of binding the body's controller method reference to the onclick of the footer button save. 
onclick: bodyComp.getReference("c.saveMyrecord")