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

How to use react-input-mask with Input? #783

Closed
perevezencev opened this issue Jan 17, 2018 · 6 comments
Closed

How to use react-input-mask with Input? #783

perevezencev opened this issue Jan 17, 2018 · 6 comments
Labels
Projects

Comments

@perevezencev
Copy link

perevezencev commented Jan 17, 2018

<Input
  {...input}
  valid={!meta.touched ? null : meta.valid}
  type="tel"
  placeholder={placeholder}
  tag={InputMask}
/>

This sample doesn't work. How to apply mask to Input component?

@supergibbs
Copy link
Collaborator

supergibbs commented Jan 29, 2018

Can you make an example on stackblitz? You can use https://stackblitz.com/edit/reactstrap-v5a4-starter as a base

@perevezencev
Copy link
Author

Example on codesandbox https://codesandbox.io/s/pxyo9y36q

@TheSharpieOne
Copy link
Member

With all of the tag manipulation going on within Input, it doesn't seem to honor the tag passed in.

TheSharpieOne added a commit that referenced this issue Jan 30, 2018
@supergibbs supergibbs added this to To Do in v5.0.0-beta via automation Jan 30, 2018
v5.0.0-beta automation moved this from To Do to Done Jan 30, 2018
TheSharpieOne added a commit that referenced this issue Jan 30, 2018
@TheSharpieOne
Copy link
Member

TheSharpieOne commented Jan 31, 2018

Give it a try with the latest release (reactstrap@5.0.0-beta)
https://stackblitz.com/edit/reactstrap-v5beta-input-mask?file=Example.js

jlaramie pushed a commit to jlaramie/reactstrap that referenced this issue Mar 9, 2018
@gabriellemos
Copy link

It is possible to use with react-input-mask and react-hook-form?

https://stackblitz.com/edit/reactstrap-v5beta-input-mask-yu6zii?file=Example.js

@TheSharpieOne
Copy link
Member

TheSharpieOne commented Dec 11, 2019

Using the latest version of those libs, it is possible to use them together.
react-hook-form requires a ref on the input, and react-input-mask allows you to get a ref using inputRef. Supplying the ref provided by react-hook-form to inputRef does the trick.
https://stackblitz.com/edit/reactstrap-v5beta-input-mask-ch8dsm?file=Example.js

import React from "react";
import { Input } from "reactstrap";
import useForm from "react-hook-form";
import InputMask from "react-input-mask";

const Example = () => {
  const { register, handleSubmit, errors } = useForm();
  const onSubmit = data => console.log(data);

  console.log(errors);

  return (
    <div>
      <form onSubmit={handleSubmit(onSubmit)}>
        <label>react-hook-form</label>
        <Input
          type="text"
          name="input-1"
          invalid={errors["input-1"]}
          innerRef={register({ required: true })}
        />
        <br />
        <label>react-input-mask</label>
        <Input
          type="tel"
          mask="+4\9 99 999 99"
          maskChar=" "
          name="masked"
          invalid={errors["masked"]}
          inputRef={register({ required: true })}
          tag={InputMask}
        />
        <br />
        <input type="submit" />
      </form>
    </div>
  );
};

export default Example;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
v5.0.0-beta
  
Done
Development

No branches or pull requests

4 participants