How to use text-mask-addons - 10 common examples

To help you get started, we’ve selected a few text-mask-addons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github formio / formio.js / src / components / number / Number.js View on Github external
this.delimiter = this.options.thousandsSeparator || separators.delimiter;
    }
    else {
      this.delimiter = '';
    }

    this.decimalLimit = getNumberDecimalLimit(this.component);

    // Currencies to override BrowserLanguage Config. Object key {}
    if (_.has(this.options, `languageOverride.${this.options.language}`)) {
      const override = _.get(this.options, `languageOverride.${this.options.language}`);
      this.decimalSeparator = override.decimalSeparator;
      this.delimiter = override.delimiter;
    }
    this.numberMask = createNumberMask({
      prefix: '',
      suffix: '',
      requireDecimal: this.component.requireDecimal ?? false,
      thousandsSeparatorSymbol: this.component.thousandsSeparator ?? this.delimiter,
      decimalSymbol: this.component.decimalSymbol ?? this.decimalSeparator,
      decimalLimit: this.component.decimalLimit ?? this.decimalLimit,
      allowNegative: this.component.allowNegative ?? true,
      allowDecimal: this.component.allowDecimal ?? !this.component.validate?.integer,
      fillGaps: this.component.decimalLimit && this.component.requireDecimal,
    });
  }
github redgeoff / mson-react / src / mson / fields / number-field.js View on Github external
_createMask(props) {
    const maskOpts = {
      prefix: '', // override default of '$'
      allowDecimal: true,
      decimalLimit: null,
      allowNegative: true
    };

    MASK_PROPS.forEach(name => {
      if (props[name] !== undefined) {
        maskOpts[name] = props[name];
      }
    });

    this.set({ mask: createNumberMask(maskOpts) });
  }
github formio / ngFormio / src / directives / formioMask.js View on Github external
}

        var mask;
        if (scope.component.inputMask) {
          // Text or other input mask, including number with inputMask.
          mask = formioUtils.getInputMask(scope.component.inputMask);
        }
        else if (format === 'currency') {
          maskOptions.prefix = scope.prefix;
          maskOptions.suffix = scope.suffix;
          // Currency mask.
          mask = createNumberMask(maskOptions);
        }
        else if (format === 'number') {
          // Numeric input mask.
          mask = createNumberMask(maskOptions);
        }
        else if (format === 'datetime') {
          mask = formioUtils.getInputMask((scope.component.format.replace(/[hHmMyYdD]/g, '9').replace(/[a]/g, 'P')));
          mask.forEach(function(item, index) {
            if (item === 'P') {
              mask[index] = /[AP]/;
              mask.splice(index + 1, 0, /[M]/);
            }
          });
        }

        // Set the mask on the input element.
        if (mask) {
          scope.inputMask = mask;
          maskInput({
            inputElement: input,
github instacart / Snacks / src / components / Forms / DateField.js View on Github external
import React from 'react'
import createAutoCorrectedDatePipe from 'text-mask-addons/dist/createAutoCorrectedDatePipe'
import omit from '../../utils/omit'
import MaskedTextField, { maskedTextFieldPropTypes } from './MaskedTextField'

const mask = [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/]
const hint = 'MM/DD/YYYY'
const pipe = createAutoCorrectedDatePipe('mm/dd/yyyy')

const getValue = value => value

export const dateFieldPropTypes = omit(
  maskedTextFieldPropTypes,
  'type',
  'mask',
  'maskHint',
  'pipe',
  'getValue',
  'ref'
)

class DateField extends React.Component {
  static propTypes = dateFieldPropTypes
github bullhorn / novo-elements / projects / novo-elements / src / elements / time-picker / TimePickerInput.ts View on Github external
ngOnInit(): void {
    this.placeholder = this.military ? this.labels.timeFormatPlaceholder24Hour : this.labels.timeFormatPlaceholderAM;
    this.maskOptions = {
      mask: this.military ? [/\d/, /\d/, ':', /\d/, /\d/] : [/\d/, /\d/, ':', /\d/, /\d/, ' ', /[aApP上下]/, /[mM午]/],
      pipe: this.military ? createAutoCorrectedDatePipe('HH:MM') : createAutoCorrectedDatePipe('mm:MM'),
      keepCharPositions: false,
      guide: true,
    };
  }
github bullhorn / novo-elements / projects / novo-elements / src / elements / date-picker / DatePickerInput.ts View on Github external
ngOnInit() {
    this.userDefinedFormat = this.format ? !this.format.match(/^(DD\/MM\/YYYY|MM\/DD\/YYYY)$/g) : false;
    if (!this.userDefinedFormat && this.textMaskEnabled && !this.allowInvalidDate) {
      this.maskOptions = this.maskOptions || {
        mask: this.dateFormatService.getDateMask(),
        pipe: createAutoCorrectedDatePipe(this.format || this.labels.dateFormatString().toLowerCase()),
        keepCharPositions: false,
        guide: true,
      };
    } else {
      this.maskOptions = { mask: false };
    }
  }
github bullhorn / novo-elements / src / platform / elements / time-picker / TimePickerInput.ts View on Github external
ngOnInit(): void {
    this.placeholder = this.military ? this.labels.timeFormatPlaceholder24Hour : this.labels.timeFormatPlaceholderAM;
    this.maskOptions = {
      mask: this.military ? [/\d/, /\d/, ':', /\d/, /\d/] : [/\d/, /\d/, ':', /\d/, /\d/, ' ', /[aApP]/, /[mM]/],
      pipe: this.military ? createAutoCorrectedDatePipe('HH:MM') : createAutoCorrectedDatePipe('mm:MM'),
      keepCharPositions: false,
      guide: true,
    };
  }
github sumup-oss / circuit-ui / src / components / CurrencyInput / CurrencyInputService.spec.js View on Github external
it('should handle currency/locale pairs with decimal period and thousands comma separators', () => {
      const currency = 'USD';
      const locale = 'en-US';
      const expectedDecimalSymbol = '.';
      const expectedThousandsSeparatorSymbol = ',';
      createCurrencyMask(currency, locale);
      const options = createNumberMask.mock.calls[0][0];
      const actualDecimalSymbol = options.decimalSymbol;
      const actualThousandsSeparatorSymbol = options.thousandsSeparatorSymbol;
      expect(actualDecimalSymbol).toEqual(expectedDecimalSymbol);
      expect(actualThousandsSeparatorSymbol).toEqual(
        expectedThousandsSeparatorSymbol
      );
    });
github sumup-oss / circuit-ui / src / components / CurrencyInput / CurrencyInputService.spec.js View on Github external
it('should handle currency/locale pairs with no fractional part', () => {
      const currency = 'CLP';
      const locale = 'es-CL';
      const expectedAllowDecimal = false;
      const expectedDecimalLimit = 0;
      createCurrencyMask(currency, locale);
      const options = createNumberMask.mock.calls[0][0];
      const actualAllowDecimal = options.allowDecimal;
      const actualDecimalLimit = options.decimalLimit;
      expect(actualAllowDecimal).toEqual(expectedAllowDecimal);
      expect(actualDecimalLimit).toEqual(expectedDecimalLimit);
    });
github OasisDEX / oasis-react / src / components / MaskedTokenAmountInput.jsx View on Github external
render() {
    const newProps = {...this.props.input};

    newProps.disabled = this.props.disabled;
    newProps.onChange = this.forwardEvent(this.props.input.onChange);
    newProps.onBlur = this.forwardEvent(this.props.input.onBlur);

    return (
        
    );
  }
}