Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Below is the JavaScript that makes this work.  It is written very generically so to apply to your form all you have to do is copy it into the onShow event of the Survey widget where you want this "ranking" behavior enforced.

Code Block
languagejs
linenumberstrue
if(!app.getSharedData().rankSetup)
{
/* This global flag insures that the function will only get called once */
    app.getSharedData().rankSetup = true;
    var children = field.getChildren();

    var createlisteningFunction = function(item){
       return (function(){
          var value = item.getValue();
          if(value.length === 0)
             return;

                    /* clears the value of the other items if they share the same rank value */          
                    for(var i=0; i<children.getLength();i++)
          {
              if(children.get(i) === item)
                 continue;
              if(children.get(i).getValue() === value)
                 children.get(i).setValue("");
          }
       });
    };
    /*create and attach a listener function to each questions onChange event*/
    for(var i=0; i<children.getLength(); i++)
    {
        children.get(i).getBOAttr().connectEvent('onChange', createlisteningFunction(children.get(i)));
    }
}

...