Skip to content
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

[Request] Input Mask Right to Left #33

Open
benitogonzalezh opened this issue Sep 21, 2020 · 7 comments
Open

[Request] Input Mask Right to Left #33

benitogonzalezh opened this issue Sep 21, 2020 · 7 comments

Comments

@benitogonzalezh
Copy link

benitogonzalezh commented Sep 21, 2020

Add an option to apply the mask from right to left in the input.

Example with RL option activated:

Mask
##.###.###-#

Expected Behaviur
17.173.127-2
2.412.412-5

Normal Behaviur (how it works now)
17.173.127-2
24.124.125

@mateusfccp
Copy link

I also need this for currency masking.

For example, if I have a currency mask and I input "1", I expect the mask to be applied as $ 00.1 instead of $ 1, starting from the cents, right to left.

@diego-lipinski-de-castro

Any updates on this?

@daybson
Copy link

daybson commented Nov 18, 2020

Still....

@diego-lipinski-de-castro

You can use this code

inputFormatters: <TextInputFormatter>[
                            // _moneyMaskFormatter
                            TextInputFormatter.withFunction(
                                (oldValue, newValue) {
                              String newText = newValue.text
                                  // .replaceAll(MoneyTextFormField._cents, '')
                                  .replaceAll('.', '')
                                  .replaceAll(',', '')
                                  .replaceAll('_', '')
                                  .replaceAll('-', '');

                              String value = newText;
                              int cursorPosition = newText.length;

                              if (newText.isNotEmpty) {
                                value = _formatCurrency(
                                  double.parse(newText),
                                );
                                cursorPosition = value.length;
                              }

                              return TextEditingValue(
                                text: value,
                                selection: TextSelection.collapsed(
                                  offset: cursorPosition,
                                ),
                              );
                            }),
                          ],
String _formatCurrency(num value) {
    ArgumentError.checkNotNull(value, 'value');

    value = value / 100;

    return NumberFormat.currency(
      // customPattern: '###.###,##',
      customPattern: '###,###.##',
      // locale: 'pt_BR',
    ).format(value);
  }

@yuriescl
Copy link

I need this feature as well

@giovannism20
Copy link

giovannism20 commented Jul 22, 2021

I couldn't quite understand what you want so I can't implement :/ - if someone can explain it better, I can worry about implementing what I'm currently working on the financial mask

@jheimes-silveira
Copy link

this tip was very useful, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants