I have created a record edit form and I am passing fields dynamically from field sets.
Below is the HTML code where it display only 1 field at a time.
I want to display 2 columns instead of one.
LWC HTML:
<template>
<lightning-record-edit-form object-api-name={sfdcObjectApiName} record-type-id={recTypeId}
onsuccess={handleSuccess}>
<lightning-messages></lightning-messages>
<lightning-accordion allow-multiple-sections-open active-section-name={activeSection}>
<template for:each={fields_per_section} for:item="accordion_item">
<lightning-accordion-section key={accordion_item.label} name={accordion_item.label}
label={accordion_item.label}>
<template class="slds-grid slds-gutters slds-col slds-size_6-of-12" for:each={accordion_item.fields}
for:item="fieldFromSubsection">
<lightning-input-field key={fieldFromSubsection} field-name={fieldFromSubsection}
name={fieldFromSubsection} id={fieldFromSubsection}>
</lightning-input-field>
</template>
</lightning-accordion-section>
</template>
</lightning-accordion>
</lightning-record-edit-form>
</template>
I have tried to use slds-size_6-of-12 but its not working. Can someone please me what I am doing wrong here?
I would also like to know if there's possibility to add an icon in accordion section or on the header. I read somewhere that it's not possible to add icon in accordion section
Best Answer
Based on your requirements, you need to add a respective class to the lightning-accordion section.
For example -
If you want to show two fields side by side with label stacked over the input, then use slds-form-element_compound class to the section.
If you need label placed side by side with the input, then use slds-form-element_horizontal class along with slds-grid inside lightning-accordion-section
If you need label and input in 2 separate columns, then just use slds-form-element_horizontal w/o slds-gird.
To use icon, you can just add container div as shown in the code. You can poisition it using some css trick so that it looks good.
Checkout the whole code in action here. Do not hesitate to play around.
And as sfdcfox has done, you can simple do it using lightning-layout as well.