igorescobar / jQuery-Mask-Plugin

A jQuery Plugin to make masks on form fields and HTML elements.
http://igorescobar.github.io/jQuery-Mask-Plugin/
Other
4.78k stars 1.42k forks source link

Fails to integrate with JVFloat #302

Closed doublejosh closed 9 years ago

doublejosh commented 9 years ago

Float labels are another great input refinement, and should/can be used with an input mask. JVFloat is a popular library. https://github.com/maman/JVFloat.js

The jQuery-MaskPlugin inserts undefined into the text field when combined with JVFloat.

doublejosh commented 9 years ago

Able to hack around the issue by only adding the mask once input is present.

$.each($('.form-input__text'), function() {
  $(this).on('focus blur change input', function touchedInput() {
    if ($(this).val() !== '') {

      // Masks.
      if ($(this).attr('name') === 'card_num') {
        $(this).mask('0000-0000-0000-0000');
      }
      if ($(this).attr('name') === 'exp_date') {
        $(this).mask('00/00');
      }
    }

  });
});

Not great.

igorescobar commented 9 years ago

If you were able to submit a PR identifying and fixing the problem I would more than happy to merge it.