RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.4k stars 2.17k forks source link

Mask Selection seems Invalid on Complex Masks #1054

Open AlexanderMorou opened 9 years ago

AlexanderMorou commented 9 years ago

This is related to Issue #1051.

If you have a complex set of masks for say, entering a date through its long-text, selection of the valid mask seems to be incorrect.

If you have the month names encoded based on the month name lengths (due to the way cardinality works) the selection of the mask seems to be based solely on which matches first (leading to the order of the masks being important, which it shouldn't be.)

Once a mask is selected, a key-press for the next valid letter should probably (?) check to see if it spills over into other masks that also validated up to that point.

An example is the encoding of the long-text of dates in the following (human-readable format) MMMM DD, YYYY.

Encoding this as javascript to extend the definitions you get:

Inputmask.extendDefinitions(
  { 'G':
    {
      validator:   'May',
      cardinality: 3,
      prevalidator:
      [
        {
          validator:   'M',
          cardinality: 1,
        }, 
        {
          validator:   'Ma',
          cardinality: 2,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'H':
    {
      validator:   'Ju(ly|ne)',
      cardinality: 4,
      prevalidator:
      [
        {
          validator:   'J',
          cardinality: 1,
        }, 
        {
          validator:   'Ju',
          cardinality: 2,
        }, 
        {
          validator:   'Ju(l|n)',
          cardinality: 3,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'I':
    {
      validator:   'April|March',
      cardinality: 5,
      prevalidator:
      [
        {
          validator:   '(A|M)',
          cardinality: 1,
        }, 
        {
          validator:   'Ap|Ma',
          cardinality: 2,
        }, 
        {
          validator:   'Apr|Mar',
          cardinality: 3,
        }, 
        {
          validator:   'Apri|Marc',
          cardinality: 4,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'J':
    {
      validator:   'August',
      cardinality: 6,
      prevalidator:
      [
        {
          validator:   'A',
          cardinality: 1,
        }, 
        {
          validator:   'Au',
          cardinality: 2,
        }, 
        {
          validator:   'Aug',
          cardinality: 3,
        }, 
        {
          validator:   'Augu',
          cardinality: 4,
        }, 
        {
          validator:   'Augus',
          cardinality: 5,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'K':
    {
      validator:   'January|October',
      cardinality: 7,
      prevalidator:
      [
        {
          validator:   '(J|O)',
          cardinality: 1,
        }, 
        {
          validator:   'Ja|Oc',
          cardinality: 2,
        }, 
        {
          validator:   'Jan|Oct',
          cardinality: 3,
        }, 
        {
          validator:   'Janu|Octo',
          cardinality: 4,
        }, 
        {
          validator:   'Janua|Octob',
          cardinality: 5,
        }, 
        {
          validator:   'Januar|Octobe',
          cardinality: 6,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'L':
    {
      validator:   'December|February|November',
      cardinality: 8,
      prevalidator:
      [
        {
          validator:   '(D|F|N)',
          cardinality: 1,
        }, 
        {
          validator:   '(D|F)e|No',
          cardinality: 2,
        }, 
        {
          validator:   'Dec|Feb|Nov',
          cardinality: 3,
        }, 
        {
          validator:   'Dece|Febr|Nove',
          cardinality: 4,
        }, 
        {
          validator:   'Decem|Febru|Novem',
          cardinality: 5,
        }, 
        {
          validator:   'Decemb|Februa|Novemb',
          cardinality: 6,
        }, 
        {
          validator:   'Decembe|Februar|Novembe',
          cardinality: 7,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'M':
    {
      validator:   'September',
      cardinality: 9,
      prevalidator:
      [
        {
          validator:   'S',
          cardinality: 1,
        }, 
        {
          validator:   'Se',
          cardinality: 2,
        }, 
        {
          validator:   'Sep',
          cardinality: 3,
        }, 
        {
          validator:   'Sept',
          cardinality: 4,
        }, 
        {
          validator:   'Septe',
          cardinality: 5,
        }, 
        {
          validator:   'Septem',
          cardinality: 6,
        }, 
        {
          validator:   'Septemb',
          cardinality: 7,
        }, 
        {
          validator:   'Septembe',
          cardinality: 8,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'B':
    {
      validator:   '0[1-9]|[1-2][0-9]|3[0-1]',
      cardinality: 2,
      prevalidator:
      [
        {
          validator:   '[0-3]',
          cardinality: 1,
        }
      ]
    }
  });
Inputmask.extendDefinitions(
  { 'N':
    {
      validator:   '1(89[5-9]|9[0-9][0-9])|2(0[0-9][0-9]|1([0-2][0-9]|3[0-5]))',
      cardinality: 4,
      prevalidator:
      [
        {
          validator:   '[1-2]',
          cardinality: 1,
        }, 
        {
          validator:   '1[8-9]|2[0-1]',
          cardinality: 2,
        }, 
        {
          validator:   '1(89|9[0-9])|2(0[0-9]|1[0-3])',
          cardinality: 3,
        }
      ]
    }
  });

Inputmask.extendDefinitions(
  { 'E':
    {
      validator:   '[0-9][0-9]',
      cardinality: 2,
      prevalidator:
      [
        {
          validator:   '[0-9]',
          cardinality: 1,
        }
      ]
    }
  });

Using the following 'mask' set: 'M B, E', 'M B, N', 'L B, E', 'L B, N', 'K B, E', 'K B, N', 'J B, E', 'J B, N', 'I B, E', 'I B, N', 'H B, E', 'H B, N', 'G B, E', 'G B, N'

In this example, you can never type 'April', 'May', 'June', or 'July' into the input mask controlled text field.

The Cardinality issue from #1051 also shows up here causing the four digit year to sometimes be untypeable, likely (?) due to the DD portion selecting the incorrect cardinality on some inputs.

AlexanderMorou commented 7 years ago

Robin,

Has there been any progress on this?