Resolved phone inputs IO-722
This commit is contained in:
@@ -6,6 +6,8 @@ function FormItemCurrency(props, ref) {
|
||||
{...props}
|
||||
ref={ref}
|
||||
style={{ width: "initial" }}
|
||||
formatter={(value) => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
|
||||
parser={(value) => value.replace(/\$\s?|(,*)/g, "")}
|
||||
// formatter={(value) => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
|
||||
// parser={(value) => value.replace(/\$\s?|(,*)/g, "")}
|
||||
precision={2}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import { Input } from "antd";
|
||||
import i18n from "i18next";
|
||||
import parsePhoneNumber from "libphonenumber-js";
|
||||
import React, { forwardRef } from "react";
|
||||
import PhoneInput from "react-phone-input-2";
|
||||
import "react-phone-input-2/lib/high-res.css";
|
||||
import "./phone-form-item.styles.scss";
|
||||
|
||||
function FormItemPhone(props, ref) {
|
||||
return (
|
||||
<PhoneInput
|
||||
country="ca"
|
||||
onlyCountries={["ca", "us"]}
|
||||
ref={ref}
|
||||
className="ant-input"
|
||||
<Input
|
||||
// country="ca" ref={ref} className="ant-input"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
@@ -21,30 +17,15 @@ export default forwardRef(FormItemPhone);
|
||||
|
||||
export const PhoneItemFormatterValidation = (getFieldValue, name) => ({
|
||||
async validator(rule, value) {
|
||||
if (!getFieldValue(name)) {
|
||||
if (!value) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
const p = parsePhoneNumber(getFieldValue(name), "CA");
|
||||
|
||||
if (p) {
|
||||
const p = parsePhoneNumber(value, "CA");
|
||||
if (p.isValid()) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
return Promise.reject(i18n.t("general.validation.invalidphone"));
|
||||
}
|
||||
}
|
||||
|
||||
// PhoneInput({
|
||||
// value: getFieldValue(name),
|
||||
// isValid: async (value, country) => {
|
||||
// console.log("value", value);
|
||||
// if (value.match(/12345/)) {
|
||||
|
||||
// } else if (value.match(/1234/)) {
|
||||
// return false;
|
||||
// } else {
|
||||
// return Promise.resolve();
|
||||
// }
|
||||
// },
|
||||
// });
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user