reloadOptions not working

Hello, friends,

I can’t seem to get select control options to load from a PHP script.

First, here are the DHX libraries I’m using:

[code]

[/code]

Here is the ‘select’ control definition from the form’s JSON:

{type: "select", inputWidth: 150, name: "buyers", label: "Buyer", connector: "http://intranet-dev/prBuyers.php"}

And here is the JavaScript code for loading the options:

bForm.reloadOptions("buyers", "http://intranet-dev/prBuyers.php");

The back-end PHP connector code, prBuyers.php, emits this string:

[{text:"Christopher Pike",value:"cpike@abc.org"},{text:"Tiberius Kirk",value:"tkirk@abc.org"}]

But the ‘buyers’ select control options do not get populated. Nothing seems to happen.

However, if I change the JavaScript code to consume a hard-coded string:

bForm.reloadOptions("buyers", [{text:"Christopher Pike",value:"cpike@abc.org"},{text:"Tiberius Kirk",value:"tkirk@abc.org"}]);

… the ‘buyers’ select control options get correctly populated.

Please help me find a solution. I’ve looked into the dhtmlxform_dyn.js extension library code, and the ‘dhtmlXForm.prototype.reloadOptions’ part seems to be getting executed. The value of the ‘name’ argument being passed to it is ‘buyers’, and the value of the ‘data’ argument being passed to it is ‘http://intranet-dev/prBuyers.php’. I assume this is as it should be.

Thank you.

Ajaxian

Hello again,

I found this recent forum post:

forum.dhtmlx.com/viewtopic.php?f=17&t=50365

I used a similar approach:

window.dhx4.ajax.post("prBuyers.php", function(response){ bForm.reloadOptions("buyers", window.dhx4.s2j(response.xmlDoc.responseText)); });

… and it seems to work. However, the solution was provided by the poster and not by DHX staff. I would still like to know, please, if you have a different solution, especially since this one doesn’t appear to be documented for the ‘reloadOptions’ method.

Thank you again.

Ajaxian

reloadOptions cannot be used with the separate pages and ajax requests. You can use only with the local objects.
So, as to the suggested solution, you need to perform the ajax-request to get the options as the local object and then use this object in the reloadOptions method.