Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

[Added] nuPrompt() JavaScript function

Information about updates, news, Code Library
Post Reply
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

[Added] nuPrompt() JavaScript function

Unread post 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]);
 }
}
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: [Added] nuPrompt() JavaScript function

Unread post 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.
Post Reply