question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use react-input-mask with Input?

See original GitHub issue
<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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
TheSharpieOnecommented, 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

5reactions
TheSharpieOnecommented, 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;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing react-input-mask for web apps - LogRocket Blog
The react-input-mask library renders masked input boxes using typical HTML inputs. Therefore, you can change styling by adding CSS classes as ...
Read more >
react-input-mask - npm
Start using react-input-mask in your project by running `npm i ... There are 907 other projects in the npm registry using react-input-mask.
Read more >
GitHub - sanniassin/react-input-mask
Apply mask only if value is not empty. In general, this is the most reliable solution because we can't be sure about formatting...
Read more >
react-input-mask examples - CodeSandbox
Learn how to use react-input-mask by viewing and forking react-input-mask example apps on CodeSandbox.
Read more >
Input Mask in React without libraries - DEV Community ‍ ‍
Step 5: ... import React, { useState, useEffect, useRef } from 'react'; const InputMask = () => { const [card, setCard] = useState();...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found