@rnga/orders
Version:
## Get schema from @prisma-cms 1. yarn get-api-schema -e http://localhost:4000 2. yarn build-api-fragments
92 lines (58 loc) • 1.6 kB
JavaScript
/**
* Выводит форматированный номер заказа и слаба
*/
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import NumberFormat from "react-number-format";
class OrderNumberField extends Component {
valueToText = value => {
// return value ? value.replace(/[^0-9]/g, '') : "";
// return "111111111111";
value = value ? value.substr(0, 10).split("").reduce((current, next, index) => {
if (index === 1 || index === 6) {
current.push("/");
}
current.push(next)
return current
}, []) : [];
return value.join("");
}
render() {
const {
name,
onChange,
...other
} = this.props;
return <NumberFormat
// format={value => {
// value = value ? value.substr(0, 10).split("").reduce((current, next, index) => {
// if (index === 2 || index === 6) {
// current.push("/");
// }
// current.push(next)
// return current
// }, []) : [];
// return value.join("");
// }}
format={this.valueToText}
removeFormatting={value => {
return value ? value.replace(/[^0-9]/g, '') : "";
}}
onValueChange={(values, event) => {
const {
value,
} = values;
onChange && onChange({
target: {
name,
value,
},
});
}}
// renderText={this.valueToText}
{...other}
// type="text"
/>
}
}
export default OrderNumberField;