implement a MaskedTextBox that displays the country flag

1 Answer 301 Views
MaskedTextBox
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Tejas asked on 07 Jul 2023, 07:06 AM

How can I implement a MaskedTextBox that displays the country flag automatically when a country code like +1 or +2 is entered for a phone number?

 

import * as React from "react";
import * as ReactDOM from "react-dom";
import {
  MaskedTextBox,
  InputPrefix,
  InputSuffix,
} from "@progress/kendo-react-inputs";
import { Button } from "@progress/kendo-react-buttons";
import { Icon } from "@progress/kendo-react-common";
const prefix = () => (
  <InputPrefix>
    <Icon name="user" />
  </InputPrefix>
);
const suffix = () => (
  <InputSuffix>
    <Button themeColor="primary" fillMode={"flat"} rounded={null}>
      Send
    </Button>
  </InputSuffix>
);
const App = () => {
  return (
    <div>
      <div>Number:</div>
      <MaskedTextBox
        prefix={prefix}
        suffix={suffix}
        mask="(999) 000-00-00-00"
        defaultValue="(359) 884-12-33-21"
        width={300}
      />
    </div>
  );
};  

1 Answer, 1 is accepted

Sort by
0
Wissam
Telerik team
answered on 10 Jul 2023, 10:40 AM

Hello, Tejas,

Thank you so much for providing a code sample.

You can achieve this by controlling the MaskedTextBox value and dynamically rendering a flag based on the component's value.

In the below example, when changing the value to start with either `+1` or `+2`, the Icon rendered inside the InputPrefix changes to a share icon. In your case, you can render a country flag instead:

For more information on rendering the MaskedTextBox in controlled mode, check the following article:

I hope this helps, but please let me know if you have any further questions.

Regards,
Wissam
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Tags
MaskedTextBox
Asked by
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Wissam
Telerik team
Share this question
or