aFarkas/remote-list

Adding and Accessing Additional Property

cevarief opened this issue · 4 comments

Is there a way to access additional data property ? Let say i have this data
code : 0001
value : A Product Name
label : A Product Label

I would like to trigger onSelect and get property code, so i could put the product code in a hidden input.

How can i get 0001 rather than A Product Name which can be duplicate (same name but different product code).

I check this $('#mytextdata').remoteList('selectedData') return input element, while in demo page http://afarkas.github.io/remote-list/demo/ it returns correct data.

Solved: I made a little hack to the $.fn.remoteList. I set variable inst to false if it is PlainObject and set variable ret to instRet. So onSelect $(this).remoteList('selectedData') now returns correct data object {value: "A product Name", code: "0001", label: "A Product Label"}

@cevarief
Could you please show me your code change. Actually it should already without any changes.

           if (inst && $.isPlainObject(inst)) {
                markupOpts = inst;
                //inst = false; // <-- Comment this
            }

            if (inst && inst[fn]) {
                instRet = inst[fn].apply ? inst[fn].apply(inst, args || []) : inst[fn];
                if (instRet !== undefined) {
                    ret = instRet; // <-- Add this, so it returns instance rather than this (variable ret)
                    return false;
                }
            } else {
                $(this).data('remoteList', new RemoteList(this, $.extend({}, opts, markupOpts)));
            }

CMIIW.

@cevarief
Thanks, I haven't purely understood why this change is needed. Seems that the $.isPlainObject itself sometimes returns true, although should return false. (Maybe a inst instanceof RemoteList check?) I solved it a little bit different, but should work with your code now.

Could you please review? Thanks.