Giter Club home page Giter Club logo

Comments (3)

falkoschindler avatar falkoschindler commented on July 22, 2024 1

Oh, nice catch, @Ezbaze! I think I understand:

When calling r.props('min=10 max=90'), we're setting r._props['min'] = '10' and r._props['max'] = '90'. Both limits are treated as strings, because .props() can't recognize data types. Quasar's QRange, however, doesn't seem to be able to handle strings as range limits, which causes the strange behavior.

When we update the limits by writing floats to r._props, the range element behaves nicely:

r = ui.range(min=0, max=100, value={'min': 30, 'max': 70})

def change_limits():
    r._props.update(min=10, max=90)
    r.update()

ui.button('Change limits', on_click=change_limits)
ui.label().bind_text_from(r, 'value', str)

So we don't even need PR #3242. But we should provide a public API for changing min and max to avoid this data type confusion.

from nicegui.

falkoschindler avatar falkoschindler commented on July 22, 2024

Here is a minimum example:

r = ui.range(min=0, max=100, value={'min': 30, 'max': 70})
ui.button('Change limits', on_click=lambda: r.props('min=10 max=90'))
ui.label().bind_text_from(r, 'value', str)

After changing the limits, adjusting the range causes it to disappear and the value is None.

A plain Quasar example works fine though:

<html>
  <head>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.prod.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div id="q-app">
      <q-range v-model="range" :min="rangeLimits.min" :max="rangeLimits.max"></q-range>
      <q-btn label="Change limits" @click="changeLimits"></q-btn>
      <div>Current range: {{ range.min }} - {{ range.max }}</div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.umd.prod.js"></script>
    <script>
      const app = Vue.createApp({
        data() {
          return { range: { min: 30, max: 70 }, rangeLimits: { min: 0, max: 100 } };
        },
        methods: {
          changeLimits() {
            this.rangeLimits = { min: 10, max: 90 };
          },
        },
        setup() {
          return {};
        },
      });
      app.use(Quasar);
      app.mount("#q-app");
    </script>
  </body>
</html>

Does anyone have an idea?

from nicegui.

Ezbaze avatar Ezbaze commented on July 22, 2024

This seems to be caused by the missing : in front of the prop names, adding those in seems to fix the issue, but I'm unsure why.

Modified minimum example:

from nicegui import ui

r = ui.range(min=0, max=100, value={"min": 30, "max": 70})
ui.button("Change limits", on_click=lambda: r.props(":min=10 :max=90"))
ui.label().bind_text_from(r, "value", str)

ui.run()

I also submitted a draft pull request with the changes: #3242

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.