I'm using lightning-record-edit-form
in the component, inside that i've input-field with required set to true
<lightning-record-edit-form record-type-id={recordType} object-api-name="Case" onsubmit={handleSubmit}>
<lightning-input-field field-name='Api Name' required=true></lightning-input-field>
...... with several other input fields
<lightning-button class="slds-m-top_small" variant="brand" type="submit" label="Submit">
</lightning-record-edit-form>
When i click on Submit without filling required the focus does not go to the required field/s. Unless user scroll up and down may not realize missing required fields.
Any solution ?
EDIT :
This problem exists for Picklist fields only not for normal Text.
Best Answer
You should receive a deployment error if you specify the required attribute in that way. See the error I received trying to do the same thing you have in your example:
I would recommend changing your attribute to only "required" (see below), verify that it deploys, and then test.
What is the data type of the field? That could also be a factor if it's a picklist. Only the following HTML tags will obey the required attribute in a form:
Worst case scenario, you may have to do write your own validation.
EDIT: If you need to do your own validation, you need to add the logic to your
onsubmit
event handler,handleSubmit()
. The handleSubmit method returnstrue
if you want the submit to continue forward orfalse
if you need to stop it for whatever reason. So your handleSubmit will look something like this: