I'm trying to figure out why when I call setupControlBox from within the $.getJSON call it works (in the if condition) but if I call it from the else condition it throws an undefined error (I set opts.load_url to false). Does the call have to be encapsulated in $.someFunction()?
// Load existing form data
if (opts.load_url) {
$.getJSON(opts.load_url, function(json) {
form_db_id = json.form_id;
fromJson(json.form_structure);
opts.loaded(json);
var controlBox = setupControlBox(opts.control_box_target);
});
} else {
var controlBox = setupControlBox(opts.control_box_target);
}