retrieving selected value from dynamic ipOpts

retrieving selected value from dynamic ipOpts

neustarneustar Posts: 9Questions: 3Answers: 0
edited October 2014 in Editor

I've read this thread (http://datatables.net/forums/discussion/9899/datatable-editor-form-select-ipopts-dynamic-values) and generally designed my code in the same manner. But it behaves poorly when trying to read the selected value in preSubmit. I have a 'custName' select field where the ipOpts is set up by the below function:

function getCustList(){
    var xx = [];
    $('#custsel > option').each(function() {
        var $this = $(this); 
        if ($this.text().substring(0,13) !='All Customers')
            xx.push( { label: $this.text(), value: $this.val } );
    });
    return xx;
}

with this Editor snippet to call the above fn:

            }, {
                type: "select",
                label: "Cust Name:",
                name: "custName",
                ipOpts: getCustList()

So far, so good. When I am in the create popup the list is populated with simple text strings as expected. On preSubmit however, the custName field is not giving me the users text selection it is giving me an entire js function:

"function (a){var b,c,d,e=this[0];{if(arguments.length)return d=m.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,m(this).val()):a,null==e?e="":"number"==typeof e?e+="":m.isArray(e)&&(e=m.map(e,function(a){return null==a?"":a+""})),b=m.valHooks[this.type]||m.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=m.valHooks[e.type]||m.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(lc,""):null==c?"":c)}}:"

My static selects in other ipOpts fields behave fine, so obviously something is foo. Any ideas?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    $this.val

    Could you try making that:

    $this.val()
    

    Or alternatively this.value.

    It looks like the above might be returning a jQuery function since it isn't being executed.

    Allan

  • neustarneustar Posts: 9Questions: 3Answers: 0

    great guess. turns out in my getCustList fn, although it was populating the ipOpts visibly fine it was not fine. I changed it slightly

    FROM: xx.push( { label: $this.text(), value: $this.val } );

    TO: xx.push( { label: this.text, value: this.value } );

    And it made all the diff at preSubmit time. No idea why, but thx

This discussion has been closed.