How to use dependent() to update one select field values from another field
How to use dependent() to update one select field values from another field
I've looked at ur example regarding the dependent(), but still cannot figure it out. The following is the situation. The user select the department and I will update the staff select fields.
editor.dependent('e.deptid', funciton(val, data, callback) {
var staffids= $.ajax({
url : "ajax/staffs_json.php",
data : {
"action" : "getRecords4Select_All",
"deptid" : $("#deptid").val();
},
type : 'post',
cache : false,
async : false,
dataType: 'json',
success : function(json) {
callback(json);
}
});
};
This discussion has been closed.
Answers
Hi,
Thanks for posting the code. The basic okay looks okay - two questions though:
e.deptid
(the first parameter passed into the function) - is that intentional? (Unless you are giving that input element in the Editor form the id#deptid
using some callback, rather than the Editor assigned id.)json
(or more specifically, what does the object contain?).Thanks,
Allan
Got the problem solved. All I have to do is return an options array with the data I want to put for the form's selection field, just like the first I got the data from the server. The following is the code I use:
The only different is the server's reply data format.
Reply with Values array & Options array.
{"values":{"e.staffid":"All"},"options":{"e.staffid":[{"label":"\u5168\u90e8","value":"All"},{"label":"ASDaf","value":"4234"},{"label":"BCE","value":"23223234"}]}}
Good to hear you've got it sorted. If there is any particular part of the
dependent()
documentation you found confusing, I'd certainly be interested in knowing so I can try to improve it.Allan
I would suggest that you could put an dependent() example on the web for getting data from the server triggerred by a Select field. The reason is that I don't use ur server pdo class, I use mine. And I just need to know the data format being exchanged between.
The example you put is hide/show, don't help me a lot to understanding the data flow.
Superb feedback - thanks! I will look at adding that!
Allan