Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"input" example allows line breaks in phone number #908

Open
psychon opened this issue Jul 30, 2024 · 1 comment
Open

"input" example allows line breaks in phone number #908

psychon opened this issue Jul 30, 2024 · 1 comment

Comments

@psychon
Copy link

psychon commented Jul 30, 2024

Hi there,

I was looking around how to have a number-only input field in ftxui 5.0.0 and came across the input example:

// We are using `CatchEvent` to filter out non-digit characters.
Component input_phone_number = Input(&phoneNumber, "phone number");
input_phone_number |= CatchEvent([&](Event event) {
return event.is_character() && !std::isdigit(event.character()[0]);
});
input_phone_number |= CatchEvent([&](Event event) {
return event.is_character() && phoneNumber.size() > 10;
});

While playing around with this example, I noticed that the "Return" key is allowed to add line breaks to the telephone number. That does not feel like it is intended.

(For my own use I got rid of this by having multiline = false in the options of the input component, see

bool HandleReturn() {
if (multiline()) {
HandleCharacter("\n");
}

@HiperDoo
Copy link

I also noticed this problem, by default it is in multiline mode (in my case it is totally inconvenient since I have many cells where parameters are filled with keywords).

But there is a simple solution without the need to edit the source code:

ftxui::InputOption input_option() {
      ftxui::InputOption option{ftxui::InputOption::Default()};
      option.multiline = false;
      return option;
  }

std::string name = "Name Example";
ftxui::Component input_field{ftxui::Input(&name, name, input_option())};

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

No branches or pull requests

2 participants