Giter Club home page Giter Club logo

Comments (2)

BorisMoore avatar BorisMoore commented on August 17, 2024

I think the best approach would be to use converters, in order, first, to convert from the number data type of your underlying data (next_bid) to the string data type displayed/returned by in an <input>, and back to number when the input is updated.

You can then choose to have the converter from number to string also format to 2 decimal places, etc etc,

$.views.converters({
  dec: function(value) {
    return value.toFixed(2); // return number as string formatted to 2 decimal places
  },
  toNum: function(val) {
    return +val; // Convert string to number
  }
});
<input data-link="{:next_bid:toNum}"/><br/><br/>
<input data-link="{dec:next_bid:toNum}"/><br/><br/>
<a data-link="next_bid">Bid</a>

<input data-link="next_bid.toFixed(2)"/> won't work because by default data-link will bind to the leaf item in the data path, in this case the 'computed' toFixed(2), (see https://www.jsviews.com/#linked-paths@deep), whereas you want to bind to next_bid.

You could specify the two-way binding to next_bid by writing <input data-link="next_bid^toFixed(2) linkTo=next_bid"/>, but even there, you still need to convert to number, and therefore to write <input data-link="{:next_bid^toFixed(2) linkTo=next_bid:toNum}"/>, so you might as well use the simpler approach above of doing everything in the dec and toNum converters...

Let me know if this works for you...

from jsviews.

BorisMoore avatar BorisMoore commented on August 17, 2024

Resolving as a question (not a bug)

from jsviews.

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.