react-hook-form-mui icon indicating copy to clipboard operation
react-hook-form-mui copied to clipboard

Url validation doesn't seem to work?

Open hypergig opened this issue 1 year ago • 1 comments
trafficstars

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the latest version

Current behavior 😯

When using

  <TextFieldElement
    autoComplete="off"
    fullWidth
    label="Url"
    name="url"
    type="url"
    required
    variant="standard"
  />

Url validation doesn't seem to occur

Expected behavior 🤔

I would expect to see a validation error with helper text saying "Url is not valid"

Steps to reproduce 🕹

Steps:

  1. Add provided TextFieldElement
  2. Enter an invalid url string
  3. Submit

hypergig avatar Jan 28 '24 18:01 hypergig

@hypergig react-hook-form-mui doesn't add a url validation when you specify the type="url" for input field. Try adding a validation using the validation prop.

  validation={{
    pattern: {
      value: /^(https?):\/\/[^\s/$.?#].[^\s]*$/,
      message: 'Please enter a valid url',
    },
  }}

sadik-malik avatar Mar 01 '24 03:03 sadik-malik

this is changed in v7 beta and rules property is providing this functionality

dohomi avatar Apr 08 '24 03:04 dohomi