Skip to content

Problems creating an input that allows positive and negative decimal values #4209

Closed Answered by falkoschindler
ronniebax asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for reporting this problem, @ronniebax! I created issue #4210 to further investigate the minus key event subscription.

As a workaround you can subscribe to any "keydown" event and handle the individual key codes in Python:

def handle_key(event: events.GenericEventArguments) -> None:
    if event.args['key'] == '+':
        ui.notify('You pressed the + key')
    if event.args['key'] == '-':
        ui.notify('You pressed the - key')

ui.input().on('keydown', handle_key)

But I'll leave this discussion open in case someone from the community has a better idea how to created masked inputs for signed numbers. (Did you think about using ui.number?)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ronniebax
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
community question A question for the NiceGUI community
2 participants