dohomi/react-hook-form-mui

Url validation doesn't seem to work?

Closed this issue · 2 comments

Duplicates

  • I have searched the existing issues

Latest version

  • 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 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',
    },
  }}

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