I was trying to port the 0.4 combobox with incremental database search. However, it seems that the url now is only called once, instead of getting called every time the user input changes. This makes incremental searching impossible. Also, the seachString does not seem to be supported either. In other words, suggest.php is only called once, and the search string was not passed to the script either. Any help is greatly appreciated.
Here is the test file:
<head>
<title>ComboBox Widget Dojo Tests</title>
<style type="text/css">
@import
"http://o.aolcdn.com/dojo/0.9.0/dijit/themes/tundra/tundra.css";
@import "http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.css"
</style>
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.xd.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileReadStore");
function setVal2(value) {
console.debug("Selected "+value);
}
</script>
</head>
<body class="tundra">
<div dojoType="dojo.data.ItemFileReadStore" jsId="schoolStore"
url="/suggest.php?school=%{searchString}"></div>
<input dojoType="dijit.form.ComboBox"
autoComplete="true"
store="schoolStore"
value=""
searchAttr="name"
name="school2"
onChange="setVal2" />
</body>
<title>ComboBox Widget Dojo Tests</title>
<style type="text/css">
@import
"http://o.aolcdn.com/dojo/0.9.0/dijit/themes/tundra/tundra.css";
@import "http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.css"
</style>
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.xd.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileReadStore");
function setVal2(value) {
console.debug("Selected "+value);
}
</script>
</head>
<body class="tundra">
<div dojoType="dojo.data.ItemFileReadStore" jsId="schoolStore"
url="/suggest.php?school=%{searchString}"></div>
<input dojoType="dijit.form.ComboBox"
autoComplete="true"
store="schoolStore"
value=""
searchAttr="name"
name="school2"
onChange="setVal2" />
</body>

Another Solution
I have (nearly) the same problem. I don't understand the handling of the url within the ComboBox-Code. Let me explain my solution I tried:
function init(){
tmpUrl = { url: "http://localhost:8080/dojoapp/dojoServlet",
form: "myForm"
}
var store = new dojo.data.ItemFileReadStore(tmpUrl);
combo = new dijit.form.ComboBox({
name:"prog",
autocomplete:true,
store: store,
searchAttr:"name"
}, dojo.byId("articleSubType"));
}
dojo.addOnLoad(init);
Now, it doesn't work. So I start to debug the code, cause I was surprise (well, at least not, cause it would be to easy ;-) ). So, I found the following Code in the function _forceLoad in ItemFileReadStore.
var getArgs = {
url: self._jsonFileUrl,
handleAs: "json-comment-optional",
sync: true
};
var getHandler = dojo.xhrGet(getArgs);
Why is not my url-Object used? Why is the form-Tag not in use? It's a bug or a feature? The same handling is used in all other methods.
Would be nice to get an answer. Maybe I missunderstand something.
Greetings
Andre
If I were you..
I'm a complete Dojo noob - but I think what you're trying to do is something like "Google Suggest"
If your data set is reasonable, use a filteringSelect. The initial payload is the only bandwidth required - the rest is done client side.
hope this helps..
Large and/or dynamic Data Set
Well, sure, if I only have a few item, I could transfer the data complete to the client. But, like Google Suggest, I would update the items based on the String you insert and based on the state of the form (like another SelectBox).
SAME PROBLEMS WITH COMBO
Hi Johnshen,
I've problems with combo in dojo 0.9, too. My code is very similar to your. This is my code for populating datastore (I'm using Java/Spring) by Url:
...
<div dojoType="dojo.data.ItemFileReadStore" jsId="doctorStore"
url="searchdoctorflex.do?&name=%{searchString}&namelike=true"></div>
...
Debugging the application with Firebug I've seen that url was is only called once.
Adding a breakpoint into the controller code I've seen that the "name" parameter value passed to It was NULL, too.
Have you ever resolved the problem?
Is "searchString" not longer supported by Dojo 0.9?
Reload the Combobox
Hi,
after I debug the Code I used the following Hack. Hope there will be a officiel solution in the Version 1.0:
To force the Reload after every pressed key or click use:
dojo.addOnLoad ( function() {
dojo.connect(dojo.byId("myCombo"), 'onkeypress', update);
dojo.connect(dojo.byId("myCombo"), 'onfocus', update);
});
function update() {
dijit.byId("myCombo").store._loadFinished = false;
}
To send the parameter of the form, you have to 'patch' the File 'ItemFileReadStore.js'.
in the constructor add the following codeline:
this._jsonFileUrl = keywordParameters.url;
this._formName = keywordParameters.form; //new
this._jsonData = keywordParameters.data;
Now you have to add a line three parts of the Code:
var getArgs = {
url: self._jsonFileUrl,
form: self._formName, //new
handleAs: "json-comment-optional"
};
It works well, but at least it is a Bad hack. Or is there a easier way?
so...
I'm looking to do the same thing - and you are right that a filtering select will only work well for smallish data sets.
does the code you provided above work in all browsers? would you recommend use it?
Thank you so much, I am so much closer, just one more question
I got the incremental search with your help, jamari. Really appreciate it. However, I still did not get the parameter back, at least the way I did in 0.4, beause the request parameter was passed literally, instead of fetching from the input node, as seen in the httpd log:
suggest.php: $_GET = Array( [school] => %{searchString}
as you can see, the server did not see the user input. Rather it is just getting invoked as originally written in the code. Do you have any idea what I should do to pass the user input to the backend script (suggest.php)? Thanks in advance.
Did the Browser send the Parameter
Hi,
when I understand you right, you don't get the Parameter of the textfield as a GET-Parameter in the request. But you should get all parameter of the form in the request. Did you 'patch' the javascript-sources correctly. [In this Moment i would like to ask a dojo-developer how dojo-user should do it correctly].
Maybe you have a look of the request after sending. Use Tamper [a Firefoxplugin] or Charls, Ethereal to check.
i patched it as you have specified, and got all parameters
jamari, i patched it as you have posted. also, i print out both the $_POST (which includes all form variables) and $_GET (query string) arrays. the user input is nowhere to be found. thanks for any ideas!
[jshen@eduoutz data]$ diff -u ItemFileReadStore.js~ ItemFileReadStore.js
--- ItemFileReadStore.js~ 2007-08-20 10:38:17.000000000 -0700
+++ ItemFileReadStore.js 2007-09-14 09:59:04.000000000 -0700
@@ -42,6 +42,7 @@
this._arrayOfTopLevelItems = [];
this._loadFinished = false;
this._jsonFileUrl = keywordParameters.url;
+ this._formName = keywordParameters.form; //new
this._jsonData = keywordParameters.data;
this._datatypeMap = keywordParameters.typeMap || {};
if(!this._datatypeMap['Date']){
@@ -289,6 +290,7 @@
this._loadInProgress = true;
var getArgs = {
url: self._jsonFileUrl,
+ form: self._formName, //new
handleAs: "json-comment-optional"
};
var getHandler = dojo.xhrGet(getArgs);
Still a problem
Hi,
is the problem solved (i like the solution from wolfram)? You have to change more then one time these part:
var getArgs = {
url: self._jsonFileUrl,
+ form: self._formName, //new
handleAs: "json-comment-optional"
};
cu
jamari
not yet
i made changes in all 3 places of getArgs, but still the user input is not passed to the cgi script. i printed out the _GET, _POST and _SERVER arrays (that is all the data that the server is likely to receive from the request) and the user input is nowhere to be found.
i copied wolfram's code and how to use example, but could not get it to work at all. there was no error, but no request sent.
thanks,
--john
My 0.9 solution, fixed
in the example i wrote:
... dojoType="app.widget.Tagcombobox" ...but it must be
... dojoType="dijit.form.ComboBox" ...this should be it: http://dpaste.com/hold/20107/
or what are the problems you are experiencing, can i help?
cu
Wolfram
ComboBoxDataStore... (line 5)
Wolfram, I copied and pasted your file as well as the example. This is what I got in firebug:
dojo.data has no properties ComboBoxDataStore... (line 5)
[Break on this error] dojo.declare("app.widget.ComboBoxDataStore",dojo.data.ItemFileReadStore, {
your code
Johnshen, did you exactly copy the code?
may be come online in the irc channel "dojo", discussing it live is a bit easier (i am cain in there) just ping me there, i will be around from time to time
cu
Wolfram
http://devois.ucop.edu/ois/testcombonew.html
here is my page.
i copied your script faithfully, i think. i had to add some commenting characters because its format changed when i copy and pasted. Thanks!
your script is installed:
http://devois.ucop.edu/ois/ComboBoxDataStore.js
I will try to find you in irc.
@johnshen
@johnshen - did you ever figure this out? can you post here or email me if you did (joe dot travaglini @ gmail dot com)
thanks
sorry, no, the same error
No, I have not been able to get it work. I posted the error and links above and it stays the same. Maybe you could check it too, to see where the problem could be. Thanks!
My 0.9 solution
http://dpaste.com/hold/19878/
dojo.provide("app.widget.ComboBoxDataStore"); dojo.require("dojo.string"); dojo.declare("app.widget.ComboBoxDataStore", dojo.data.ItemFileReadStore, { // This is just for backing up the URL actually passed to the constructor. _orginialJsonFileUrl: null, _fetchItems: function( /* Object */ keywordArgs, /* Function */ findCallback, /* Function */ errorCallback){ // This is quite a dirty hack for making the 0.9 ComboBox reload data from the // server everytime a user changes the content of the combobox. // Just the 0.4 dataUrl="/url/${serachString}" beahviour. // This is quite ugly because it "knows" how the _fetchItems() method of the // parent class works, if that one will be changed in its behaviour it MIGHT // affect this hack and will make it not work anymore. // // Usage: // // // if (this._orginialJsonFileUrl===null) { this._orginialJsonFileUrl = this._jsonFileUrl; } // Well we never loaded all the data, since we want a reload every time a key is hit. this._loadFinished = false; // The parent _fetchItems method uses this._jsonFileUrl and we need it to have // the searchString replaced. this._jsonFileUrl = dojo.string.substitute(this._jsonFileUrl, {searchString:keywordArgs.query.name.replace(/\*$/, "")}); app.widget.ComboBoxDataStore.superclass._fetchItems.apply(this, arguments); this._jsonFileUrl = this._orginialJsonFileUrl; } });cu
Wolfram
Wolfram's 0.9 solution and FilteringSelect
Any idea why, using FilteringSelect instead of ComboBox, when first loading the page, I see a HTTP request where the ${searchString} part is *not* replaced? After that it works ok.
Why does it even make a HTTP request on page load when nothing has even been typed into the field yet?
Also, what's the app.widget.Tagcombobox widget mentioned in the comments for the code up in dpaste?
"app.widget.Tagcombobox" should be "dijit.form.ComboBox"
"app.widget.Tagcombobox" was my custom widget, just ignore it.
about ur other problem: its probably some FilteringSelect specialty, l had a glimpse but didnt see it right away
cu
Wolfram
I made this change in my test file listed above, but same error
Wolfram,
could not find you in irc. i made the above change in my test file but got the exact same error. As you can see, the file I have in the link is a verbatim copy of your without any change. thanks for any ideas.
hack of ItemFileReadStore
ItemFileReadStore is designed to download all the data from the specified url when it's initialized, and then handle all queries (ie, filtering, etc.) client side. Wolfram hacked it to query the server every time but clearly that initial query is still happening, so has to be disabled somehow.
not ItemFileReadStore
The problem is that you are using ItemFileReadStore, which by design downloads all the data in the URL on page load. You need a different datastore. Unfortunately the datastore you want hasn't been written yet (or at least not checked in yet). See bug 4116.
It works
Bill, I got the above mentioned solution working and its not loading the data on page load, but exactly when i need them and that is either
* when i click the down-button it loads (all the backend serves) or
* when i type a letter it then loads the data (using the search string) and provides them for autocompletion
cu
Wolfram
cool
Cool, that looks pretty good. I wouldn't call it ComboBoxDataStore but rather something like RemoteFetchDataStore. The only downside is probably pulling in a bunch of code in ItemFileReadStore that presumably isn't being used (specifically sorting and filtering code). BTW I cut/pasted your code into the post above since the link you provided will self-destruct in 30 days.
0.9 : the Wolfram way, problem.
Hi Wolfram,
I'm looking to follow your path.
I've created a datastore from your code. (ComboBoxDataStore.js)
Placed it in the dojo.data directory & changed the 2 references in the file to this.
But now I'm not sure what comboBox code to use.
I have this...
This seems to result in the error message...
(in FireFox with FireFox)
any idea?
I know the servlet gets called when th page is loaded, but then nothing after that.
Thanks for your help.
Jeff Porter
try this
app is surely the namespace i used, so i guess the error is in the datastore class,
did you use this piece of code: http://dpaste.com/hold/19878/
then you must change it accordingly to this
http://dpaste.com/20893/ (i hope its ok)
if not, you can also ping me in irc (i am "cain" there)
cu
Wolfram
thanks
I'm getting there now.
missed an occurance in the datastore file.
one last question..
ignore this.
it is now so so close now, just one last small step away
This new file now works by passing path_info to the cgi script.
However, when the script returns (by writing to the stdout) a jason array as specified in dijit/tests/form/comboBoxData.json, the combobox does not use it. You can see that otherwise the script is working fine:
http://devois.ucop.edu/ois/testcombonew.html
Thanks!
i tried it, no data comes back
hi johnshen,
i tried your url and it calls http://devois.ucop.edu/ois/ois2dot0/suggest.php/ but firebug says
SyntaxError: syntax error message=syntax error
and the response says "Loading..." so its still a server issue it seems.
also trying it by hand
>>> dojo.xhrGet({url:"/ois/ois2dot0/suggest.php/a"})
returns the same, is it possible that your server script crashes after the call? looks like it, because the response doesnt hang for a long time
just my guess from far away (i guess)
cu
Wolfram
a solution, the right way
http://trac.dojotoolkit.org/ticket/4597
there i implementd a real dojo.data store, that loads the data from the backend as discussed here, the advantage of this solution: it is the right way (still incomplete) and it's a suggestion for dojo(x).data
cu
Wolfram
so is this in 0.9 now???
Wolfram,
I'm very new around here and so I'm not sure about the release cycle for 0.9....is your patch now in the 0.9 dojo download?
I checked the ticket and it sounds like patch has been accepted and checked in?
Is it really as easy to now use this as your little bit of code in the ticket summary?
Thanks!
Nathan
its in SVN and will be in 1.0 (which is coming very soon)
you are talking about the QueryReadStore, yes that is in the svn trunk now and ready to be used.
be sure to wait for this patch http://trac.dojotoolkit.org/ticket/4761 to go in
and you should be good to use it
cu
Wolfram
Anyway I could get your patch early?
Wolfram,
I downloaded the 1.0Beta and then also last night's build, and am not seeing your patch in the dojox folder....I also poked around some in SVN looking for your code, but didn't see it anywhere in there...I'm suspecting that its one of the "committers" (http://svn.dojotoolkit.org/dojo/ROOT/view/committer 7633)? folders that I can get access to with just anonymous....
Ordinarily, I'd be more than happy to wait until it arrives in an offiicial nightly build, but I'm doing a proof of concept for a few people, and I sure would like to be able to use the latest patch so that I can use a filteringSelect rather than just the ComboBox (which works pretty very btw) that you made avaialble in: http://trac.dojotoolkit.org/ticket/4597
If you could conceivably zip up the patches and email them to me (npoe@weathershield.com) , (along with a new usage example?) or just put them out somewhere in the cloud, I sure would appreciate it!
Thanks so much!
Nathan
The patch is an attachment to the ticket 4761
please find the patch here
http://trac.dojotoolkit.org/ticket/4761
use simply the last attachments i posted names something like "final patch"
cu
Wolfram
almost there...
Wolfram,
I got all the changes pasted in from the patches.....when I run the QueryReadStore.html, I get this error:
message : missing ) in parenthetical fileName : http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js lineNumber : 20 stack : ()@:0 eval("('.json_encode(array('items'=>$ret)).')")@:0 ("'.json_encode(array('items'=>$ret)).'")@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 ([object XMLHttpRequest])@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 ([object XMLHttpRequest])@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 ([object Object])@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 ()@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 ([object Object])@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 ([object Object])@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 ([object Object])@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 (-18)@http://localhost:8080/dojoTests2/assets/js/dojotoolkit/dojo/dojo.js:20 @:0 name : SyntaxErrorthat ".json_encode(array('items'=>$ret))...." comes from the /dojox/tests/stores/QueryReadStore.php is there a new version of that .php file that will fix this prob?
Thanks!
Nathan
php not running. may be?
iirc i had that too on a server where no php was running :-)
might try a server with php or install php.
verify that the /dojox/tests/stores/QueryReadStore.php is executed and that you dont get back the pure php file
cu
Wolfram
well...Duh.
Yes that was it. I would roll my eyes at my developers if they asked me that question. ;)
So yes, this works very very well indeed. And extremely (and surprisingly) fast performance...! Thank you very much for your work on this.
Both Combox Box and Filtering select are able to use the QuerySReadStore, which is cool...but the filteringSelect doesn't seem to respond to the "labelAttrr" and "labeltype" attributes. The end result (at least for me) is that I can't embed images in my FilteringSelect results...or is there another way to achieve this?
here's what my filtering select currently looks like:
anything jump out at you?
nathan
cool, but i still got an error
i copied your latest patch. everything else seems to work, but got the following error:
GET https://devois.ucop.edu/ois/tests/QueryReadData.php?q=al (70ms)dojo.js (line 20)
ParamsHeadersPostResponse
Response Headers
Request Headers
{"items":[{"name":"Alabama","label":"Alabama"
,"abbreviation":"AL"},{"name":"Alaska","label":"Alaska","abbreviation":"AK"}]}
Error: dojox.data.QueryReadStore: a function was passed an item argument that was not an item
I think that I can resolve your problem....
Hi everybody, I'm a frenchy so excuse my bad english.
The last week I had to develop an autocompleter which give some city results with a postal code parameter in the url query like that:
"http://localhost/ComboBoxDate.jsp?departement=59" so when I modified the code the results was the same that the results of the first call.
So, in order to resolve this problem I had reset the store of my ComboBox like that:
function changeCode(numCode) {
cityComboBox.store = new dojo.data.ItemFileReadStore({url: "http://localhost/comboBoxData.jsp?departement=" + numCode } );
}
And this solution works perfectly.
in your case (johnshen) you could write this for resolving your problem:
<title>ComboBox Widget Dojo Tests</title>
<style type="text/css">
@import "http://o.aolcdn.com/dojo/0.9.0/dijit/themes/tundra/tundra.css";
@import "http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.css"
</style>
<script type="text/javascript" src="http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.xd.js" djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileReadStore");
</script>
</head>
<body class="tundra">
Your search : <input id="input_id" />
<script type="text/javascript">
function setSchoolParam(value) {
/* reinitialisation of the ComboBox Store */
school2.store = new dojo.data.ItemFileReadStore({url: "/suggest.php?school=" + value );
}
/* Creation of the dataStore */
var schoolStore = new dojo.data.ItemFileReadStore({url: "/suggest.php" );
/* Creation of the ComboBox for the input input_id */
var school2 = new dijit.form.ComboBox({id: "school2",
autoComplete: true,
store: schoolStore,
searchAttr: "name",
name: "school2",
onChange: setSchoolParam},
dojo.byId("input_id");
</script>
</body>
Have a nice day everyone.
Regards.
Jocker :D
Wolfram's QueryRead...
I can't get the FilteringSelect to work with the QueryData store. When I try to set an identity field, I get the following error:
Error: dojo.data.QueryReadStore: The json data as specified by: [undefined] is malformed. Items within the list have identifier: [value]. Value collided: [undefined]
My dataset looks like this:
{
'identifier':"value",
items: [
{'value':'26', 'name':"Admin"}
,
{'value':'25', 'name':"Administrative Ant"}
]
}
Without the "identifier" I can't ID the field for the filtering select. Is there a workaround, or am I doing something wrong?
Relevant markup:
(div dojotype="dojox.data.QueryReadStore" jsid="qrs3157" url="/auto_completion/auto_complete_title")
(div autocomplete="true" dojotype="dijit.form.FilteringSelect" id="title_id" name="title_id" store="qrs3157")
Thanks,
Ryan