Dependent editor field not updated with $.ajax call in function
Dependent editor field not updated with $.ajax call in function
I have this method as a dependent call for fetching some data from the back and assiging the return value to "bezeichnung". The AJAX call is executed correctly, however there is no update of the field. The approach works without the AJAX call with some dummy data. Anything missing here?
function cas_nr_to_str(cas_nr) {
$.ajax({
url: `/gefahrenstoffe/${cas_nr}/json`,
type: 'GET',
dataType: 'json',
async: false,
success: function(data) {
var cas_str = data.cas_str;
return {
values: {
bezeichnung: cas_nr + "x"
}
};
},
error: function(error) {
console.error('Error:', error);
}
});
}
editor_create.dependent('cas_nr', cas_nr_to_str);
editor_edit.dependent('cas_nr', cas_nr_to_str);
This question has an accepted answers - jump to answer
Answers
The
return
is returning inside the success function - which goes nowhere. Editor doesn't see that. You need to use a callback function that is passed in as the third parameter to your handling function bydependent()
:Allan
Thanks!