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

MASKs input Text_Field with bug #4408

Open
1 task done
VictorDeon opened this issue Nov 21, 2024 · 2 comments
Open
1 task done

MASKs input Text_Field with bug #4408

VictorDeon opened this issue Nov 21, 2024 · 2 comments
Labels
status: awaiting response Further information is requested

Comments

@VictorDeon
Copy link

Duplicate Check

Describe the requested feature

I've developed a CNPJ normalization within the on_change of the TextField, but it keeps selecting the value and when I type it again it goes out because it's selected, I've tried autofocus, focus and etc and nothing works, can anyone help me?

I don't know if there is another way to do this, or if this is a bug, but it would be interesting to have this functionality to create masks for inputs.

ft.TextField(
  label="CNPJ",
  hint_text="33.933.606/001-39",
  filled=True,
  on_change=normalize_cnpj
)
 
def normalize_cnpj(e: ft.ControlEvent): 
        field: ft.TextField = e.control
        cnpj: str = field.value
 
        digits = "".join(filter(str.isdigit, cnpj))
 
        if len(digits) <= 2:
            field.value = digits
        elif len(digits) <= 5:
            field.value = f"{digits[:2]}.{digits[2:5]}"
        elif len(digits) <= 8:
            field.value = f"{digits[:2]}.{digits[2:5]}.{digits[5:8]}"
        elif len(digits) <= 12:
            field.value = f"{digits[:2]}.{digits[2:5]}.{digits[5:8]}/{digits[8:12]}"
        elif len(digits) <= 14:
            field.value = f"{digits[:2]}.{digits[2:5]}.{digits[5:8]}/{digits[8:12]}-{digits[12:14]}"
        else:
            field.value = f"{digits[:2]}.{digits[2:5]}.{digits[5:8]}/{digits[8:12]}-{digits[12:14]}"
 
        field.update()

Suggest a solution

No response

Screenshots

Capturar

Additional details

No response

@VictorDeon
Copy link
Author

VictorDeon commented Nov 21, 2024

I know there's a duplicate here, but mine is more specific

@ndonkoHenri
Copy link
Contributor

Please can you share a screen recording of the issue ?

@ndonkoHenri ndonkoHenri added the status: awaiting response Further information is requested label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting response Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants