I have a component that displays a list of questions using a for:each
. For each question rendered I have a child component (which is a simple form with a few fields) to capture a followup question.
I want to be able to render the specific child component on button click on parent. The parent component looks like this -
<template for:each={list} for:item={question}>
<lightning-edit-form record-id={question.id} object-api-name="customobj__c" key={question.id}>
<lightning-output-field field-name="customfield__c" data-question={question.Name}></lightning-output-field>
<lightning-button type="submit" label="submit" onclick={handleclick} data-id={question.Name}></lightning-button>
This repeats for various fields being rendered conditionally. Submit button also is added to each field type
I want this div to show up when submit button is clicked only for that instance of question (not under every question)
<template if:true={isBool}
<div class="slds-box" data-followup={question.Name}>
<c-child-component question-id={question.Id}/>
</div>
</template>
I am trying to see if I can match the data-attribute on Submit button(data-id
) click to div(data-question
) and render that specific div.