Skip to content

InputField should verify all input changes with func accept() #147

@ardnew

Description

@ardnew

Currently, InputField will conditionally permit any input changes using the user-provided callback accept(), 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 InputField read-only:

rejectInput := func(string, rune) bool { return false }

form := tview.NewForm()
form.AddInputField("foo", "bar", 0, rejectInput, nil)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions