EasyUI Forum

General Category => Bug Report => Topic started by: 2plus2 on November 05, 2014, 04:18:12 PM



Title: Loading New Combo Data doesn't Clear Selected Option....
Post by: 2plus2 on November 05, 2014, 04:18:12 PM
We have a combo box that is loaded with data dynamically based on the user selected. We pass a JSON object to the combobox to build the dropdown instead of pulling the data from an AJAX call directly:

Code:
$('#' + trans[x] + 'InitiatorThreshold').combobox({ data: data[trans[x]].Thresholds });

If an option is selected from a previous "state", that selection is *not* cleared when the combo box is loaded with new data.

The reason it's an issue, is just after loading the new data the validType event fires:

Code:
validType: 'exists["#' + trans[x] + 'InitiatorThreshold"]'

and it fails validation with a selected option that should not persist after a reload of the dropdown options.

Is this the intended behaviour of the drop down? Currently, we are setting the value of the drop down to index "0" prior to new data being loaded in order for it always to pass validation after rebuild.


Title: Re: Loading New Combo Data doesn't Clear Selected Option....
Post by: jarry on November 05, 2014, 05:16:11 PM
Calling 'loadData' to load new data does not clear the existing value. If you want to clear the previous value, please call 'clear' method before calling 'loadData' method, or recreate the combobox again.
Code:
$('#cc').combobox('clear').combobox('loadData', newdata);
//or
$('#cc').combobox({data:newdata});


Title: Re: Loading New Combo Data doesn't Clear Selected Option....
Post by: 2plus2 on November 05, 2014, 11:38:15 PM
Thanks - but that's not it. Added it and it's still behaving as if there is an event to fire after the JSON data is loaded.

I've sent a more detailed email to support requesting help. It's very consistent. Works as expected until the validation fails, then every time we reload the drop down options with a new JSON object something runs the previous reload command and rebuilds the drop down with data we don't want / require.



Title: Re: Loading New Combo Data doesn't Clear Selected Option....
Post by: 2plus2 on November 06, 2014, 09:16:22 AM
Just for completeness, the root cause of the issue was:

We make a reload call based on certain conditions, and that sets the URL for the combobox. On load of the new JSON data for the drop down, once the URL is set the combobox makes another URL call for data using the cached URL value.

e.g.
Code:
$('#' + type + 'InitiatorThreshold').combobox('reload', '/controls/ajaxBankUsers.aspx?a=getThresholdListPlus&r=' + $('#Account').combobox('getValue') + '&i=' + $('#' + type + 'ThresholdId').val() + '&q=' + missingID);

So every time we load JSON data we need to set the URL back to null:

Code:
$('#' + trans[x] + 'InitiatorThreshold').combobox({ data: data[trans[x]].Thresholds, url: null });

(Thanks to your email support team. :-)

P.S. Not sure why both execute. I would think that when I load a JSON object for the data, that the URL wouldn't execute. But now that we know, we can avoid it.