In editviewdefs.php, I added the following JS script to obtain and dynamically fill a dropdown:
$(document).ready(function() {
$.get("URL/index.php?entryPoint=testBeans", function(data) {
let opciones = JSON.parse(data);
let select = $('#test_despl_c');
for (let i = 0; i < opciones.length; i++) {
$('<option>').val(opciones[i]).text(opciones[i]).appendTo(select);
}
});
});
ca
The problem I have is that the dropdown duplicates the values, as if the JS code is executed twice. I checked the developer tools and it seems that the problem arises because the entry point call is generated twice, and I don’t understand why.
Just a suggestion - wouldn’t it be better, instead of calling the endpoint again and using this test
if(cantOpciones.length !== opciones.length)
, if you would simply test before calling the endpoint
if(cantOpciones.length) return;
You would avoid the network delay of the second call. And it’s quite unlikely that the contents of the API response would change between the two calls…