New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize Selection in for:each Loop #154
Comments
P.P.S. I tried it in the renderedCallback of the parent component and can get the c-lookup by querySelector...but then how to set the initial value? |
Hi @mstohr1975, thanks for reaching out. You can set individual initial selections by simply applying the same technique you used for the other attributes: make this information part of your For example: nDestinations = [
{
n: 'key1',
label: 'Label 1',
selection: [ a, b, c ],
...
},
{
n: 'key2',
label: 'Label 2',
selection: [ d, e ],
...
}
]; and then: <template for:each={nDestinations} for:item="d">
<c-lookup key={d.n} class={d.class} data-id={d.n} selection={d.selection} errors={errors} onsearch={handleSearch} onselectionchange={handleSelectionChange} label={d.label} required="true" placeholder={d.placeholder}>
</c-lookup>
</template> |
Philippe, many thx for your quick and helpful feedback...obviously, this was it. 🙏 |
Close this one. |
Hi there,
I am using the lookup component within a template for:each, generating multiple entries based on a number of items. Using data-id property I can identify via querySelector the underlying component in the onsearch and onselectionchange handlers. But not sure how I can achieve the initialization of the search field. Background: I want to use it in edit mode where user might have selected results for some of the lookups and stored in database.
Is there any option to call a handler to set the initial selection? That way I could use the event passed to identify the underlying c-lookup. Alternatively, can I trigger the selection handler in parent constructor? Or maybe pass in a parameter into the Lookup class to set a class member?
Many thanks for your thoughts and feedback.
P.S. Moreover I get some validation errors related to deprecated CSS classes, namely class="slds-listbox__option-text" and class="... slds-listbox__option-meta_entity". I guess, this leads to the fact that the lookup field is slightly larger than other fields in my input form.
The text was updated successfully, but these errors were encountered: