function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SF Learner BeeSF Learner Bee 

inputField required is not working in LWC

Hi,

I have below code where the field is made required for user to enter. But its not working where the user is able to skip the field and save the record.Can someone please help me with this as I am new to development.
The code in the LWC component as shown below,
<lightning:layoutItem size = "4" padding = "around-large"-->
                <lightning:dualListbox aura:id="selectOptions"
                                       name="LSE"
                                       label= "Who do you speak with?" 
                                       sourceLabel="Available Options" 
                                       selectedLabel="Selected Options" 
                                       options="{! v.listSkillsOptions }"
                                       value="{! v.selectedSkillsItems }"
                                       onchange="{! c.handleChange }"
                                       required="true"/>
            <!--/lightning:layoutItem>

​​​​​​​
Abdul KhatriAbdul Khatri

Hi SF Learner Bee

  • If you want to make it required field just use attribute required and not required="true" or required = true
  • To not set the required field, simply remove the required attribute.
     
<lightning:layoutItem size = "4" padding = "around-large"-->
                <lightning:dualListbox aura:id="selectOptions"
                                       name="LSE"
                                       label= "Who do you speak with?" 
                                       sourceLabel="Available Options" 
                                       selectedLabel="Selected Options" 
                                       options="{! v.listSkillsOptions }"
                                       value="{! v.selectedSkillsItems }"
                                       onchange="{! c.handleChange }"
                                       required"/>
            <!--/lightning:layoutItem>
I hope this help
CharuDuttCharuDutt
Hii sf Learner
Try Below Code
<lightning:layoutItem size = "4" padding = "around-large"-->
                <lightning:dualListbox aura:id="selectOptions"
                                       name="LSE"
                                       label= "Who do you speak with?" 
                                       sourceLabel="Available Options" 
                                       selectedLabel="Selected Options" 
                                       options="{! v.listSkillsOptions }"
                                       value="{! v.selectedSkillsItems }"
                                       onchange="{! c.handleChange }"
                                       required/>
            /lightning:layoutItem>
Please Mark It As best Answer If It Helps Thank You!
 
Suraj Tripathi 47Suraj Tripathi 47

Hi,

Use the below code.

<lightning:layoutItem size = "4" padding = "around-large"-->
                <lightning:dualListbox aura:id="selectOptions"
                                       name="LSE"
                                       label= "Who do you speak with?" 
                                       sourceLabel="Available Options" 
                                       selectedLabel="Selected Options" 
                                       options="{! v.listSkillsOptions }"
                                       value="{! v.selectedSkillsItems }"
                                       onchange="{! c.handleChange }"
                                       required="true"/>
            <!--/lightning:layoutItem
Thank You
Abdul KhatriAbdul Khatri
Hi Suraj,

Is below working for you, because documentation https://developer.salesforce.com/docs/component-library/bundle/lightning-dual-listbox/specification says different 
User-added image