[GH-ISSUE #1025] InputField SetText append text instead of replacing it #744

Closed
opened 2026-03-04 01:07:26 +03:00 by kerem · 1 comment
Owner

Originally created by @CarlosMontilla on GitHub (Sep 14, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/1025

Hello,

First of all I would like to thank you for this wonderful library.

Recently I updated to the latest release 20240818110301-fd649dbf1223 from the previous one 20230325211341-281d14d896d7.

And I've encountered a strange behaviour with the InputField.SetText method in the latest version. If I take the InputField demo and add 2 consecutive SetText("12"), the resulting input field text contains the string "1212". So the second SetText had the effect of appending the string instead to the current text field of replacing it. While in the previous version, I encountered the behaviour I would expect. The second SetText replaced the string.

I leave the code below and a screenshot of what I get

// Demo code for the InputField primitive.
package main

import (
        "github.com/gdamore/tcell/v2"
        "github.com/rivo/tview"
)

func main() {
        app := tview.NewApplication()
        inputField := tview.NewInputField().
                SetLabel("Enter a number: ").
                SetPlaceholder("E.g. 1234").
                SetFieldWidth(10).
                SetAcceptanceFunc(tview.InputFieldInteger).
                SetDoneFunc(func(key tcell.Key) {
                        app.Stop()
                })

        inputField.SetText("12")
        inputField.SetText("12")
        if err := app.SetRoot(inputField, true).EnableMouse(true).Run(); err != nil {
                panic(err)
        }
}

Latest version:
image

Previous version:
image

I will keep looking to see if I find the cause of this change of behaviour, but maybe you can spot the problem faster than me.

Thank you for your support

Originally created by @CarlosMontilla on GitHub (Sep 14, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/1025 Hello, First of all I would like to thank you for this wonderful library. Recently I updated to the latest release 20240818110301-fd649dbf1223 from the previous one 20230325211341-281d14d896d7. And I've encountered a strange behaviour with the InputField.SetText method in the latest version. If I take the InputField demo and add 2 consecutive SetText("12"), the resulting input field text contains the string "1212". So the second SetText had the effect of appending the string instead to the current text field of replacing it. While in the previous version, I encountered the behaviour I would expect. The second SetText replaced the string. I leave the code below and a screenshot of what I get ```go // Demo code for the InputField primitive. package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() inputField := tview.NewInputField(). SetLabel("Enter a number: "). SetPlaceholder("E.g. 1234"). SetFieldWidth(10). SetAcceptanceFunc(tview.InputFieldInteger). SetDoneFunc(func(key tcell.Key) { app.Stop() }) inputField.SetText("12") inputField.SetText("12") if err := app.SetRoot(inputField, true).EnableMouse(true).Run(); err != nil { panic(err) } } ``` Latest version: <img width="290" alt="image" src="https://github.com/user-attachments/assets/12decf58-88a1-48cb-8a30-09b5ff7bed40"> Previous version: <img width="290" alt="image" src="https://github.com/user-attachments/assets/e589bbd1-adb5-4716-89b4-af1b6704f3b7"> I will keep looking to see if I find the cause of this change of behaviour, but maybe you can spot the problem faster than me. Thank you for your support
kerem closed this issue 2026-03-04 01:07:26 +03:00
Author
Owner

@rivo commented on GitHub (Sep 21, 2024):

Thanks. The latest commit should fix this.

<!-- gh-comment-id:2365154370 --> @rivo commented on GitHub (Sep 21, 2024): Thanks. The latest commit should fix this.
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#744
No description provided.