Giter VIP home page Giter VIP logo

Comments (3)

Lucas-lyh avatar Lucas-lyh commented on July 24, 2024

It seems like this is designed to be 0.
In elements/number.py, overwrited function _value_to_event_value function convert value to zero when value is None.
Should it keep None?

    def _value_to_event_value(self, value: Any) -> Any:
        return float(value) if value else 0

from nicegui.

frankvp11 avatar frankvp11 commented on July 24, 2024

Hmm, this is interesting.
I was playing around with this and noticed some interesting things.
Firstly, as is mentioned above, the fix for this issue would be what @Lucas-lyh described. Switch the 0 to a None and it works. I'll submit a PR for this once I get home (unless either of you want to do it @falkoschindler )
However, the reason I said this was interesting, is because I tried putting in letters into the number element. I realize that the reason you can input 'e' is because of numbers like 1e6, as this is a common representation of them. However, the reason I am intrigued is because you can put the 'e' there without a prefix. Is this the expected behaviour? Are we supposed to be able to put e7, or should we require it to have a prefix?

from nicegui.

falkoschindler avatar falkoschindler commented on July 24, 2024

@Lucas-lyh I guess you're right. The event value should also be None when clearing the number input.

Here is some code I experimented with to compare model and event values of ui.input and ui.number:

i = ui.input(placeholder='Type here').props('clearable').on_value_change(lambda e: print(f'You typed: "{e.value}"'))
ui.label().bind_text_from(i, 'value', lambda v: f'You typed: "{v}"')

n = ui.number(placeholder='Type here').props('clearable').on_value_change(lambda e: print(f'You typed: "{e.value}"'))
ui.label().bind_text_from(n, 'value', lambda v: f'You typed: "{v}"')

@frankvp11 Yes, a PR would be great!

Regarding the "e": This seems to be browser-specific behavior of the HTML input element:

ui.html('<input type="number">')

In Chrome you are allowed to type a single "e", while Safari allows to type multiple "e"s. So it's probably out of our control.

from nicegui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.