[Dojo-interest] dojo queryreadstore (filtering select) send other form data to server

mchyzer mchyzer at yahoo.com
Sun Apr 28 17:15:22 EDT 2013


I changed the Query Read Store (for filtering select) to send other form
element names with the ajax query.  It would be nice if dojo could offer
this functionality by default.  Here is a video showing this feature.

http://youtu.be/JES32ZUtO8c

Here is the HTML to specify which form element names to submit with the URL:

      <div data-dojo-type="dojox.data.QueryReadStore"
id="personPickerStoreId" formElementNamesToSend="anotherItemName"
        data-dojo-props="url:'../twoFactorUi/app/UiMain.personPicker'"
data-dojo-id="personPickerStoreDojoId"></div>
      Enter search text to find a person:<br />
        <input id="personPickerId" name="personPickerName" 
searchDelay="500" value="10021368"
          data-dojo-props="store:personPickerStoreDojoId" class="soria"
style="width: 40em"
          autoComplete="false" data-dojo-type="dijit/form/FilteringSelect"
hasDownArrow="false" />

 <input name="anotherItemName" id="anotherItemId" type="text" />

Here is the change to QueryReadStore.js

Add this function at the bottom:

/**
 * split and trim a string to an array of strings
 */
function dojoSplitTrim(input, separator) {
 if (input == null) {
   return input;
  }
  //trim the string
  input = dojoTrim(input);
 if (input == null) {
   return input;
  }
  //loop through the array and trim it
 var theArray = input.split(separator);
 for(var i=0;theArray!=null && i<theArray.length;i++) {
     theArray[i] = dojoTrim(theArray[i]);
  }
  return theArray; 
}

/**
 * trim all whitespace off a string
 */
function dojoTrim(x) {
  if (!x) {
    return x;
  }
  var i = 0;
  while (i &lt; x.length) {
    if (dojoIsWhiteSpace(x.charAt(i))) {
      i++;
    } else {
      break;
    }
  }
  if (i==x.length) {
    return &quot;&quot;;
  }
  x = x.substring(i,x.length);
  i = x.length-1;
  while (i >= 0) {
    if (dojoIsWhiteSpace(x.charAt(i))) {
      i--;
    } else {
      break;
    }   
  }
  if (i < 0) {
    return x;
  }
  return x.substring(0,i+1);
}
function dojoIsWhiteSpace(x) {
  return x==" " || x=="\n" || x=="\t" || x=="\r";
}



Then change QueryReadStore.js

Line 391:

FROM:
        var xhrFunc = this.requestMethod.toLowerCase() == "post" ?
dojo.xhrPost : dojo.xhrGet;
				var xhrHandler = xhrFunc({url:this.url,
handleAs:"json-comment-optional", content:serverQuery, failOk: true});
        request.abort = function(){


TO:

        var xhrFunc = this.requestMethod.toLowerCase() == "post" ?
dojo.xhrPost : dojo.xhrGet;

        var theUrl = this.url;
        
        //make the request dynamic, maybe send some other form element names
        var formElementNamesToSend = dojo.getAttr(this.id,
"formElementNamesToSend");
          
        if (typeof formElementNamesToSend != 'undefined' &&
formElementNamesToSend != null) {
          
          //add additional form element names to filter based on other
things on the screen
          var additionalFormElementNamesArray =
dojoSplitTrim(formElementNamesToSend, ",");
          for (var i = 0; i<additionalFormElementNamesArray.length; i++) {
            var additionalFormElementName =
additionalFormElementNamesArray[i];
            theUrl += theUrl.indexOf("?") == -1 ? "?" : "&";
            theUrl += additionalFormElementName + "=";
            //this will work for simple elements
            theUrl +=
encodeURIComponent(document.getElementsByName(additionalFormElementName)[0].value);
          }
        }

        
        var xhrHandler = xhrFunc({url:theUrl,
handleAs:"json-comment-optional", content:serverQuery, failOk: true});
        request.abort = function(){







--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/dojo-queryreadstore-filtering-select-send-other-form-data-to-server-tp3996152.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.


More information about the Dojo-interest mailing list