0 votes

Hi, is there a way to limit the number of characters that you can input in TextEdit or just a way to disable typing in it when a condition is met?

Is it possible to only accept numbers as an input. If not, is there a way to detect if the text has letters?

func _on_TextEdit_text_changed():
  if $TextEdit.get_text().length() >  5:
      #Disable Typing

Thanks :)

in Engine by (27 points)

1 Answer

0 votes

You can use property readonly of TextEdit.
"bool readonly - If true read-only mode is enabled. Existing text cannot be modified and new text cannot be added."

then add BackSpace button in Input Map for delete addition letter and change Textedit again.
enter image description here
enter image description here

by (312 points)

This works, but I have multiple TextEdit so If I press backspace all of the TextEdit.readonly will be affected. Thanks for this though, I might just go for this anyway.

Last question, does TextEdit doesn't support mobile devices? I've exported my game on android and all of the TextEdit are not showing.

You can use if stament to choose what TextEdit will be editable.
enter image description here

Sorry, what I mean is if all TextEdit are readonly, then you click backspace and everything will be back to false. Anyway, I think TextEdit doesn't work on mobile devices, so I might not use it anymore :(

Thanks for helping.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.