Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Copyright (c) Codice Foundation
*
* This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. A copy of the GNU Lesser General Public License
* is distributed along with this program and can be found at
* .
*
**/
const React = require('react')
const Group = require('../../../react-component/group/index.js')
const MaskedInput = require('react-text-mask').default
const CustomElements = require('../../../js/CustomElements.js')
const Component = CustomElements.registerReact('text-field')
class MaskedTextField extends React.Component {
render() {
// eslint-disable-next-line no-unused-vars
const { label, addon, onChange, value = '', ...args } = this.props
return (
{label != null ? (
<span>
{label}
</span>
) : null}
render() {
const { children, text, mask } = this.props;
const input = text || children;
return mask ? conformToMask(input, mask).conformedValue : input;
}
}
_conformToMask(value, mask) {
var conformed = conformToMask(value, mask, {
guide: false
});
return conformed.conformedValue;
}
export function handler(field) {
const { mask, value, maskPlaceholder } = field;
const result = conformToMask(value, mask, { placeholderChar: maskPlaceholder });
if ( result.conformedValue.indexOf(maskPlaceholder) > -1 ) {
return carbonFieldsL10n.field.wrongMask;
}
return null;
}