-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option "greedy" for translations which lets pattern greedily match #608
base: master
Are you sure you want to change the base?
Conversation
@warpspin Hello there! Can you give other application for this greedy option? |
It's basically an implementation of the regexp "+" modifier for the mask, so it's useful anywhere you have variable-width fields. Other uses I personally have are for example variable length part numbers like "manufacturer-productgroup-producttype-WIDTHxHEIGHT-variant" (e.g. something like "EG-DG1000-14568234-100x50-C") where one or more fields are variable length but we still want to require the "-" or the "x". Of course, anything the patch can do can be done by simply adding lots of "optional" keys to the mask - it just shortens the masks with a repeater. |
@warpspin and have you checked how it works with the |
Worked in my tests. I suppose the more critical combination would be if a greedy option is somehow combined with a recursive option. I don't think this would give sensible results anymore, though I haven't tried it yet. |
@warpspin Yeah... that's what I meant. I tested yesterday and it didn't worked. |
I think it's simply not a sensible combination with the way greedy is currently implemented, I can't think of a use case for it. Another possibility, though, would be to not have the greedy repetitions as a seperate feature but instead to allow explicit recursion start/end markers, like e.g.
where { would set the resetPos and } would jump back to the resetPos if the next input character matches the start of the recursion (meanings of course reverted in reverse mode). This would allow recursion to not only happen at the start or the end of input and solve all use-cases for greedy as well without needing it as a seperate feature. If you're interested in such an extended version of the feature, I'd start working on it. |
@warpspin Yeah, It can get complicated. The thing is that I believe most of the users use the What you said can become something interesting but maybe with different names, what do you think something like this: $(sel).mask('something {9.99}0 something-else', {
reverse: true,
translation: {
'{': { reverseStart: true },
'}': { reverseEnd: true }
}
}); or $(sel).mask('something {9.99}0 something-else', {
reverse: { start: '{', end: '}' }
}); I rather use But... the whole point is.... we need to see if we can add this functionality without tons of code... that's why I never focused on features to accommodate currency problems. It can get messy real fast. |
The |
@warpspin I agree but I can't think of any use case for this but with the |
This minor patch adds an option "greedy" for translations, which is a simpler but sometimes useful form of recursion: characters will be matched as long as they match, then the rest of the mask will continue to be matched.
This e.g. allows matching of traditional decimal numbers with a fixed number of fraction digits up to any length AND a sign, which is not possible with normal reverse recursive matching:
Example:
(Allows 1,23 or -1,23 or 12,23 or -12,23 and so on)
This will probably also solve most of the issues people sometimes (like #436 )have with negative numbers without a huge invasive money-related patch.