[PR #301] Added FormItem Validation #903

Open
opened 2026-03-04 01:08:29 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/rivo/tview/pull/301
Author: @mikeschinkel
Created: 6/10/2019
Status: 🔄 Open

Base: masterHead: form_validation


📝 Commits (2)

  • 06a95af Add feature-complete FormItemArgs for testing
  • 733e087 Add FormItem field validation

📊 Changes

9 files changed (+679 additions, -5 deletions)

View changed files

📝 application.go (+54 -0)
📝 box.go (+13 -0)
📝 checkbox.go (+113 -0)
📝 dropdown.go (+121 -0)
📝 form.go (+69 -5)
formitemargs.go (+48 -0)
📝 inputfield.go (+142 -0)
passwordfield.go (+112 -0)
validation.go (+7 -0)

📄 Description

This PR includes the commits for #300 because it is too hard to use without the FormItemArgs (IMO.)

This adds a .valid property and a .SetValidateFunc to each of InputField, PasswordField, DropDown and Checkbox structs.

It also adds a ValidatePrimitive(Primitive,EventKey) method to Application and calls that method inside <application>.Run() just before invoking the primitive's InputHandler().

It will only call the validation callback when event.Key() is one of
tcell.KeyEnter, tcell.KeyTab, tcell.KeyBacktab or tcell.KeyEscape.

If the callback returns false, it bypasses the input handler and keeps focus on the just now invalidated field.

Please consider accepting this update.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/rivo/tview/pull/301 **Author:** [@mikeschinkel](https://github.com/mikeschinkel) **Created:** 6/10/2019 **Status:** 🔄 Open **Base:** `master` ← **Head:** `form_validation` --- ### 📝 Commits (2) - [`06a95af`](https://github.com/rivo/tview/commit/06a95af2a234918edf0b7507018fbe534391968b) Add feature-complete FormItemArgs for testing - [`733e087`](https://github.com/rivo/tview/commit/733e0871e48155cd3729acba294db9e6dfca9e23) Add FormItem field validation ### 📊 Changes **9 files changed** (+679 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `application.go` (+54 -0) 📝 `box.go` (+13 -0) 📝 `checkbox.go` (+113 -0) 📝 `dropdown.go` (+121 -0) 📝 `form.go` (+69 -5) ➕ `formitemargs.go` (+48 -0) 📝 `inputfield.go` (+142 -0) ➕ `passwordfield.go` (+112 -0) ➕ `validation.go` (+7 -0) </details> ### 📄 Description This PR includes the commits for #300 because it is too hard to use without the `FormItemArgs` _(IMO.)_ This adds a `.valid` property and a `.SetValidateFunc` to each of `InputField`, `PasswordField`, `DropDown` and `Checkbox` structs. It also adds a `ValidatePrimitive(Primitive,EventKey)` method to `Application` and calls that method inside `<application>.Run()` just before invoking the primitive's `InputHandler()`. It will only call the validation callback when `event.Key()` is one of `tcell.KeyEnter`, `tcell.KeyTab`, `tcell.KeyBacktab` or `tcell.KeyEscape`. If the callback returns `false`, it bypasses the input handler and keeps focus on the just now invalidated field. Please consider accepting this update. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#903
No description provided.