You need to sign in to do that
Don't have an account?
riz wan
How to get Id of lightning:input in recordEditForm
I am dynamically trying to create lightning:recordEditForm by passing record Id, object name, record type id and then rendering fields using iterator.
Because of aura:iteration, all lightning:inputs have same onchange method
I want to find the id of the lightning:input which caused the onchange method to fire.
Code :
Because of aura:iteration, all lightning:inputs have same onchange method
I want to find the id of the lightning:input which caused the onchange method to fire.
Code :
<lightning:recordEditForm onsubmit="{!c.beforeSave}" onsuccess="{!c.afterSave}" recordId="{!v.obj_id}" recordTypeId="{!v.rec_type_id}" objectApiName="{!v.obj_name}"> <lightning:messages /> <aura:iteration items="{!v.form_field_list}" var="field"> <lightning:inputField aura:id="{!field.field_api}" fieldName="{!field.field_api}" onchange="{!c.handleInputChange}"/> </aura:iteration> <div class="slds-m-top_medium"> <lightning:button variant="brand" type="submit" name="save" label="Save"/> </div> </lightning:recordEditForm>
Right. aura:id takes the expression literally and cannot be set dynamically. Try using the fieldName attribute instead:
Regards,
Mkr
All Answers
You can access the aura:id attribute with following code:
- I read your problem and implemented it in my Org and it is working fine.
- Please use the below code
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
your approach give me this value in console -> {!field.field_api}
I want the id that's set by the attribute. say field_api = Type__c -> then I want to get that user changed 'Type__c' field
@Deepali
your approach gives me "undefined" in console
can you both share screenshot, in case you people are getting values
Right. aura:id takes the expression literally and cannot be set dynamically. Try using the fieldName attribute instead:
Regards,
Mkr
Earlier I was using class attribute -> event.getSource().get('v.class') and assign field_api in class.
But fieldName seems better alternative.