Page 1 of 1
[Added] nuPrompt() JavaScript function
Posted: Wed Aug 11, 2021 9:28 am
by admin
The nuPrompt() function displays a dialog box that prompts the user for input.
nuPrompt.png
Show the prompt window:
Code: Select all
nuPrompt('How are you?','Random Question');
Declare a callback function to retrieve the input value:
Code: Select all
function nuOnPromptClose(val, ok) {
if (ok) {
nuMessage(['You entered:',val]);
}
}
Re: [Added] nuPrompt() JavaScript function
Posted: Sat Jun 14, 2025 10:53 am
by kev1n
Passing callback as function reference
(available as of V.4.8-2025.06.14.05)
In addition to passing the callback as a string (the name of a function), you can also pass a function reference directly. This allows you to pass additional parameters to your callback using closures.
Example:
Code: Select all
// Some context data that you want to pass to the callback
let customerID = '12345';
let currentDate = '2025-06-14';
nuPrompt('Enter comment:', 'Add Note', '', '', function (val, ok) {
if (ok) {
saveNote(customerID, currentDate, val);
}
});
function saveNote(customerID, date, noteText) {
nuMessage(['Saving note for customer:', customerID, 'Date:', date, 'Note:', noteText]);
}
Why this is useful:
- Allows you to pass additional data into the callback (e.g. IDs, dates, context-specific values).
- Supports modern JavaScript best practices: anonymous functions, arrow functions, closures.
- Fully backward compatible — string function names are still supported.