Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Hook Form Reuired && onInput 속성 #78

Open
0gunkim opened this issue Mar 7, 2023 · 0 comments
Open

React Hook Form Reuired && onInput 속성 #78

0gunkim opened this issue Mar 7, 2023 · 0 comments
Assignees
Labels
NEWS 새로배운 것들

Comments

@0gunkim
Copy link
Contributor

0gunkim commented Mar 7, 2023

const requeirFn = (e) => {
    e.target.value = e.target.value.replace(/[^a-z]/, '');
  };
  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input
        className={styles.input}
        type="text"
        placeholder="url"
        onInput={requeirFn}
        {...register('url', {
          max: 0,
          min: 1,
          required: true,
          maxLength: 70,
          pattern: /[a-z]/i,
        })}
      />

리엑트 훅 폼에서 제공해주는 required는 Submit 이벤트가 발생 되었을 때 작동되고, 처음부터 사용자가 입력 할 때부터 제한하게 하려면 onInput속성에 로직이 필요합니다.

@0gunkim 0gunkim added the NEWS 새로배운 것들 label Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NEWS 새로배운 것들
Projects
None yet
Development

No branches or pull requests

2 participants