How to add Javascript to the current page: Add JS, CSS, HTML
jQuery is usable for any HTML output, e.g.:
String customJs = """
alert("Message entered in field: " + \$("#message").val());
""";
HTML.js(customJs);
Using the function run(..)
other scripts can be run from Javascript:
function saveEntry() {
run("add.groovy", \$("#title").val(), \$("#text").val());
}
This will run the script and then run the calling script again.
Use runWithoutReload(..)
when the page should not be reloaded after execution of the other script:
function saveEntry() {
runWithoutReload("add.groovy", \$("#title").val(), \$("#text").val());
}
Using javascript you can open the edit form for a specific record (table/id):
edit("tasks", 0); // Edit entry id=0 in table "tasks"
edit("notes", 12); // Edit entry id=12 in table "notes"
Open "Your Data" to see the names of the tables (without .json). It is the same name as you use for storing.
Example for script code to store the data (before):
// Add tasks to storage
Record task1 = new Record().set("title", "First Task");
Record task2 = new Record().set("title", "Second Task");;
STORAGE.set("tasks", Arrays.asList(task1, task2), new RecordDef().add("title");