mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #147] InputField should verify all input changes with func accept() #117
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#117
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ardnew on GitHub (Jul 30, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/147
Currently,
InputFieldwill conditionally permit any input changes using the user-provided callbackaccept(), but only if the input is a regular character (i.e.event.Key() == tcell.KeyRune). This means the callback cannot be used to conditionally permit control characters like backspace.A simple example is the callback function that renders an
InputFieldread-only:This will prevent new characters from being inserted, but it won't prevent characters from being deleted. In fact, I don't think there exists a way to prevent the user from deleting text in an
InputField(I could be wrong on this point).The same loophole exists for the key-combos Ctrl+U and Ctrl+W.
@ardnew commented on GitHub (Jul 30, 2018):
I also considered bringing the
accept()handler outside (immediately before) theswitch key := event.Key(); key { ... }block - so that it can be used to evaluate all input changes and not just the few I updated; but I wasn't sure if that kept with the spirit of your intent with that callback (since you wouldn't be able to pass in the changed text to evaluate).Perhaps a different callback should be created, or even subclassing the
InputFieldmight be preferred if you need that much control?@rivo commented on GitHub (Aug 7, 2018):
The
accept()function is not meant to be a filter on the user's keyboard actions but rather on the final text of theInputField.If you would like to intercept certain keys, you'll want to use
SetInputCapture()on theInputField.Note that I will add more key combinations in the future and a backspace will then not only affect the last character. See #103.
Let me know if this helps.
@ardnew commented on GitHub (Aug 7, 2018):
Ah, I've been misusing that callback. Thanks
Somewhat related -- can you clarify the difference or describe how I should choose between using
SetInputCapture()versus overridingInputHandler()for the case that I have a type with an embedded primitive (e.g.type MyTable struct { *tview.Table })?The docs say that defining
InputHandler()a certain way allows the use ofSetInputCapture(), but I don't understand why I would want or need to use one over the other. They appear to function the same and serve the same purpose.@rivo commented on GitHub (Aug 12, 2018):
Unless you are writing your own
Primitive, you can ignoreInputHandler(). Most applications will be fine using an existing primitive (e.g.InputField) and callingSetInputCapture()to change its input behaviour.It's only when you end up writing your own
Primitivethat you'll need to implementInputHandler()and the Wiki page you refer to gives you hints as to how to structure your code in that case.But I would think that writing one's own
Primitiveis usually not needed.I'm closing this issue. If there's still an open item, I can reopen it.