Opened 7 years ago

Closed 7 years ago

#16495 closed defect (worksforme)

ComboBox: error when using labelAttr

Reported by: retrry Owned by: Douglas Hays
Priority: undecided Milestone: tbd
Component: Dijit - Form Version: 1.8.2
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

Hello, I'm trying to use dojo JsonRest module with Tastypie and django, but I ran into problem. For tastypie you need to set filtering mechanism in URL like: name__icontains So, for ComboBox I set searchAttr to name__icontains and I set labelAttr to 'name', but when I try to select an item from dropdown list I see error in Firebug: Typeerror: this.store._oldAPI is undefined. If I delete labelAttr and set searchAttr to 'name' and sending hardcoded data from serverside value selecting works.

My example code:

  0         clientStore = new JsonRest({
  1             target: '/reminders/api/v1/client/',
  2             idProperty: 'id',
  3         });
  4         var comb = new ComboBox({
  5             id: 'select',
  6             store: clientStore,
  7             labelAttr: 'name',
  8             searchAttr: 'name__icontains',
  9             queryExpr: '*${0}*',
 10             onChange: function(val){
 11                 alert(val);
 12             },  
 13         }, 'clientView');
 14         comb.startup();

Or am I doing something wrong?

Attachments (3)

example.js (462 bytes) - added by retrry 7 years ago.
Attaching example code, 'cause pasting code borked formating
test.html (1.6 KB) - added by retrry 7 years ago.
test2.html (2.6 KB) - added by retrry 7 years ago.

Download all attachments as: .zip

Change History (16)

Changed 7 years ago by retrry

Attachment: example.js added

Attaching example code, 'cause pasting code borked formating

comment:1 Changed 7 years ago by bill

Description: modified (diff)
Owner: changed from Douglas Hays to retrry
Status: newpending

We have example code like that that works, so probably you are doing something wrong, but we can't tell without a real test case.

Please attach a self contained test case, i.e. a full HTML file.

comment:2 Changed 7 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Changed 7 years ago by retrry

Attachment: test.html added

comment:3 Changed 7 years ago by retrry

I attached requested test case. With this code I get the mentioned error. And sorry for the long delay.

Last edited 7 years ago by retrry (previous) (diff)

comment:4 Changed 7 years ago by bill

Description: modified (diff)
Resolution: invalid
Status: closedreopened
Summary: _AutoCompleterMixin.js error when using labelAttrComboBox: error when using labelAttr

Hmm, it's weird that this.store._oldAPI is involved since you are using the new dojo/store code. Looks like a bug at first glance.

comment:5 Changed 7 years ago by bill

Status: reopenedpending

I can't run the test case since it's trying to access a http://localhost/reminders/api/v1/client/ that doesn't exist on my machine.

comment:6 Changed 7 years ago by retrry

Status: pendingnew

Example for start: http://jsfiddle.net/wzgkN/5/ and I will attach same html file. At this point this example works only with dojo 1.7 branch (this doesn't work with 1.8), but that version has the same problem as 1.8 - this.store.__oldAPI is undefined.

Last edited 7 years ago by retrry (previous) (diff)

Changed 7 years ago by retrry

Attachment: test2.html added

comment:7 Changed 7 years ago by bill

Status: newpending

Thanks, that's getting better, but when I load test2.html or that jsfiddle link I don't see any error message. Is there something I need to do, or a particular browser where it fails?

comment:8 Changed 7 years ago by bill

PS: this seems to never hit the console.log:

clientStore.get(1).then(function(x){ console.log(x); })

comment:9 Changed 7 years ago by retrry

Status: pendingnew

You don't see the message as in it works, or as in it doesn't work, but I don't get error message? When you load it try to select something from dropdown list.

I'm using Firefox with Firebug on Linux, but I just tested and I get the same error on Windows box.

P.S I forgot to change dojo version in html file. I should be 1.7.4. As I said, this method doesn't work for 1.8 branch.

comment:10 Changed 7 years ago by bill

Status: newpending

Oh OK, I need to point it against 1.7.4. Yes, in that case I see the error when selecting an item from the drop down list.

The error message from firefox is misleading. The real problem is that item[this.searchAttr], in other words, item.name__icontains, is undefined. Your item is:

{"id":"2","name":"trololo"}

(there's no name__icontains property)

So... seems like a problem with your code?

Last edited 7 years ago by bill (previous) (diff)

comment:11 Changed 7 years ago by retrry

Status: pendingnew

I see what you mean... And it is quite bad position that I'm in, 'cause that means I can't have searchURL different from searchAttr which it tries to select.

I somehow managed to assume that labelAttr would become the attribute by which it tries to select, but it is only used for display reasons.

All in all this means that dojo store is not usable with REST servers which assume filtering information in URL like tastypie.

Last edited 7 years ago by retrry (previous) (diff)

comment:12 Changed 7 years ago by bill

Owner: changed from retrry to Douglas Hays
Status: newassigned

All in all this means that dojo store is not usable with REST servers which assume filtering information in URL like tastypie

Nah, it should be easy. For example, you could subclass JsonRest, overriding fetch to add that attribute to all items returned from the server.

I'm not sure though why that particular code is accessing this.searchAttr though. Doug?

comment:13 Changed 7 years ago by Douglas Hays

Resolution: worksforme
Status: assignedclosed

I assume bill's suggestion to subclass JsonRest? is working.
item[this.searchAttr] is needed to get the exact text from the store to use to fill in the INPUT, as opposed to what the user typed which may have case-differences or may not be autocompleted yet.

Note: See TracTickets for help on using tickets.