Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter Sign In with OpenID Sign In with Google

Sign In Sign Up

In this Discussion

Welcome to the Jo support forums! Please Sign Up and join in the discussion. You can also Sign In instantly with Twitter, OpenID or your Google ID.
Bug in joControl.setValueSource?
  • stewartstewart February 2011
    Posts: 11

    I linked a joSelect control to a record like this: new joSelect(languages, set.link("language"));

    This works, except when set.language is initially zero.

    I think the problem is in joControl.setValueSource:

    setValueSource: function(source) {
        this.valueSource = source;
        source.changeEvent.subscribe(this.setValue, this);
        this.setValue(source.getData() || null);
    

    If source.getData returns zero, it is replaced with null.

    I replaced this:

        this.setValue(source.getData() || null);
    

    with this:

        var data = source.getData();
        if (!data && data != 0) data = null;
        this.setValue(data);
    

    which does the same, except if getData returns zero. But I suspect this is not the best solution.

    Question: how does joDataSource.getData return "invalid result"? Presumably, it shouldn't just replace any falsy value with null, as some valid values are falsy (0, false, etc).

    Cheers, Stewart

  • davedave February 2011
    Posts: 415

    Yes, this is tricky. My temporary solution is to convert your value into a string when you save and load from your joRecord code. Not pretty, but should move your forward while I look into a solution that doesn't break anything else.

    Dave Balmer, Jo Code Wrangler
  • davedave February 2011
    Posts: 415

    Put a patch in GitHub to fix this. Would appreciate it if you pulled jo.js down from GitHub source and gave it a try without using the string hack I just mentioned. I've tested in several cases, seems to work without breaking things.

    Raw jo.js from GitHub

    Dave Balmer, Jo Code Wrangler
  • stewartstewart February 2011
    Posts: 11

    Thanks Dave. That works for me.