currently, I'm passing in a options array to the options attribute of a lightning-checkbox-group. I need to mimic the behavior of that tag, but I need to do it in html because I don't think I can get the checkboxes to display horizontally. I've tried <template for:each and have not had any luck.
My goal would be to pass in the same name/value pair array, loop through it and call the same change handler that is called when using lightning-checkbox-group.
A simple code snippet would be awesome.
This is what I've tried so far:
{lineItemObjectInfo.data.fields.Reason__c.label}
<template for:each={reasonOptions} for:item="option" for:index="index">
<div key={option}>
<lightning-input onchange={handleChange}
name={lineItemObjectInfo.data.fields.Reason__c.apiName}
type="checkbox" label={option.label}
value={recordInput.fields.Reason__c}></lightning-input>
</div>
</template>
That actually gets me pretty close. When changed it fires the change handler and fails when I'm trying to do a .join on the recordInput for the field:
handleChange(event) {
const {target: {name, value}} = event;
switch (name ) {
case "Reason__c":
this.recordInput.fields[name] = value.join(";");
break;
default:
this.recordInput.fields[name] = value;
break;
}
}
I've also tried using a form tag with input and label tags but that didn't get me much further. The switch has been reduced for purpose of making it more clear.
This is my original use of lightning-checkbox-group which functionally worked but styling is inflexible:
<div class="slds-col slds-size_3-of-12">
<lightning-checkbox-group
onchange={handleChange}
name={lineItemObjectInfo.data.fields.Reason__c.apiName}
label={lineItemObjectInfo.data.fields.Reason__c.label}
options={reasonOptions}
value={recordInput.fields.Reason__c}></lightning-checkbox-group>
</div>
lightning-checkbox-group
will only render from top to bottom. You do need to create your own component/HTML for this. Strictly speaking, we're not a code-writing service, but if you include what you've tried so far, we'll be glad to spot errors and suggestions on how to fix them.