Code Monkey home page Code Monkey logo

Comments (8)

sonhanguyen avatar sonhanguyen commented on May 22, 2024 3

Maybe my point isn't clear enough. Things like pattern, minLenght and required are already implemented in the dom API so people probably prefer to use those things. By removing those you can simplify the code and encourage web standard imo. You can just call input.checkValidity() instead of having to do the checks yourself.

from react-hook-form.

portfolioris avatar portfolioris commented on May 22, 2024 2

This would provide a great way to enable progressive enhancement. You use web standards, which will almost always work, even if loading or executing JS fails (or if users choose to disable JS). If it does execute, react-hook-form would take over, and apply custom validation instead. You set a novalidate attribute on the <form> tag by script, so the browsers knows you've taken over the validation.

from react-hook-form.

bluebill1049 avatar bluebill1049 commented on May 22, 2024

It's for validation to check if it's required or not. you can do the following:

<input required ref={register} required />

or

<input ref={register({ required: true })}>

if you want to have custom error message rather than native behavior.

from react-hook-form.

bluebill1049 avatar bluebill1049 commented on May 22, 2024

those extra options within the register argument could be useful for other validation too:

eg:

<input name="test" ref={register({ validate: (value) => value=== 'bill' })} />
{errors.test && 'name have to be bill'}

let me know your thoughts

from react-hook-form.

sonhanguyen avatar sonhanguyen commented on May 22, 2024

I assume inside register you could just read them from the input? I'm not saying those validations are not useful, just we should be able to have them simply by having those attributes on the input (if the behavior is exactly the same). Too implicit?

from react-hook-form.

bluebill1049 avatar bluebill1049 commented on May 22, 2024

yea register will hold all the input ref, so access value or error field ref is much easier. you can focus on error field without any extra work too. that's just my example, you can build your validation rules external and plug them in.

improt validateName from 'utility/validateName';

<input name="test" ref={register({ validate: validateName, minLength: 5 })} />
{errors.test && 'name have to be bill'}

from react-hook-form.

bluebill1049 avatar bluebill1049 commented on May 22, 2024

yea I get your point, you can use standard validation if you want. the choice is yours.

<input name="input" ref={regsiter} />

from react-hook-form.

bluebill1049 avatar bluebill1049 commented on May 22, 2024

hey mate, going to close this issue. let me know if you still have concerns, we can continue the discussion.

cheers
bill

from react-hook-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.