Let's say I have a Lightning-Web-Component with a select list with dynamic options where the value is a user Id and the label is the user's name:
<select class="slds-select" onchange={handleSelectChange} disabled={isDisabled}
data-value={step.selectedUser} >
<option value="">--None--</option>
<template for:each={step.approvalTemplateStep.Approval_Step_Users__r} for:item="user">
<option key={user.key} value={user.User__c}>
{user.User__r.Name}</option>
</template>
</select>
How do I prepopulate the select option with a value? I have the value I want to be prepopulated in the variable called step.selectedUser
.
Best Answer
you can declare a 'hasDefault' getter in your controller and in your template,
if:true
, render a default result option:and create a getter: