svierk / awesome-lwc-collection

⚡️ A collection of ready-to-use Lightning Web Components that might help your SFDX project
https://svierk.github.io/awesome-lwc-collection/
MIT License
164 stars 47 forks source link

Validation #20

Closed MohsinaExo closed 1 year ago

MohsinaExo commented 1 year ago

Validation is not working for the custom LWC component even after setting required as true.Can you please explain how to set validation for this custom LWC Component @svierk @sepplxy

svierk commented 1 year ago

What validation do you mean exactly? And which component are you referring to? Maybe you can give a few more details please so I can possibly help

MohsinaExo commented 1 year ago

Hello Sebastiano, I have used the Custom Picklist in a lightning-record-edit form.Even after setting required attribute to true,validation for the custom picklist is not working i.e. Form is getting submitted without even validating.can you please help.

On Tue, May 16, 2023 at 12:12 PM Sebastiano Schwarz < @.***> wrote:

What validation do you mean exactly? And which component are you referring to? Maybe you can give a few more details please so I can possibly help

— Reply to this email directly, view it on GitHub https://github.com/svierk/awesome-lwc-collection/issues/20#issuecomment-1549076278, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7WRSLDL3YPL44QRJ3FI44LXGMOUBANCNFSM6AAAAAAYA4MJO4 . You are receiving this because you authored the thread.Message ID: @.***>

-- https://exotel.com/ CONFIDENTIALITY NOTE: This e-mail is intended only for the person or entity to which it is addressed and contains information that is privileged, confidential, or otherwise protected from disclosure. Dissemination, distribution, or copying of this e-mail or the information contained herein by anyone other than the intended recipient, or an employee or agent responsible for delivering the message to the intended recipient, is prohibited. If you have received this e-mail in error, please delete this message and immediately notify the sender by e-mail.  NOTE:  This e-mail does not constitute an electronic signature and the sender does not intend to enter into any agreement by way of this e-mail, unless otherwise expressly provided by the sender within this e-mail.

svierk commented 1 year ago

Setting the required attribute in the context of a lightning-record-edit-form only brings you the little red required indicator next to the combobox label, but the validation itself you have to implement yourself, because the native validation can't be used here. So you must handle the validation for the custom picklist field in your LWC JS controller. This issue even exists with standard components like the lightning-combobox, see for example: https://salesforce.stackexchange.com/questions/291663/required-attribute-on-lightningcombobox-ignored