s-yadav / react-number-format

React component to format numbers in an input or as a text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

percentage formatting, input box <=> form state mismatch

naseemkullah opened this issue · comments

similar to #825

with something like

format={(value: string) => {
  const stripped = value.replace(/\D/g, '');
  return stripped ? `${stripped}%` : '';
}}

and an isAllowed rule allowing just 1 to 100 values, typing e.g. "555" results in 55% displayed visually, but 555 in the form state value.

Using with react-hook-form FWIW.