Welcome to the nuBuilder Forums!

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

nuPrompt() Insert into Field?

Questions related to customising nuBuilder Forte with JavaScript or PHP.
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

nuPrompt() Insert into Field?

Unread post by pmjd »

Hello,

How can you use the nuPrompt function to enter the data entered into a field on the same form?

If nuPrompt is set to trigger on change of a Select object, Is it also possible so pressing the Cancel button undoes the change to the select field?

Thanks,
Paul
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: nuPrompt() Insert into Field?

Unread post by kev1n »

Use the nuOnPromptClose callback to retrieve the entered value and assign it to a field.
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: nuPrompt() Insert into Field?

Unread post by pmjd »

The nuOnPromptClose shows how to set a nuMessage but been trying to use both nuSetValue and nuSetFormValue but neither seems to work
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: nuPrompt() Insert into Field?

Unread post by kev1n »

nuSetFormValue() is a PHP function and can't be used in JavaScript.

nuSetValue() should work if you use the latest version to set the value of a select object.

To set the selected value (numberic)

Code: Select all

nuSetValue('select_object_id', 123);
To set a text value:

Code: Select all

nuSetValue('select_object_id', 'text value', 'text')
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: nuPrompt() Insert into Field?

Unread post by pmjd »

Thanks, have managed to get it working with this

Code: Select all

function nuOnPromptClose(val, ok) {
if (ok) {
     nuSetValue('mpd_reason',val)
}
}
Is there a way of undoing the change to the select object if the cancel button is pressed on the nuPrompt modal?
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: nuPrompt() Insert into Field?

Unread post by kev1n »

What value should "undo" set ?
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: nuPrompt() Insert into Field?

Unread post by pmjd »

The idea was that if a user changed the Select value that nuPrompt would appear and ask, well demand, that they put a reason for that change in.

Select could be one of three values, so there is no default value to revert to, it would be the value last saved.

Would it be easier to disable the cancel button on nuPrompt, so if the user made a mistake they would just not save the whole record and exit?
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: nuPrompt() Insert into Field?

Unread post by kev1n »

Couldn't you store the current select value in a variable and when cancel is chosen in nuPrompt, revert to that stored value?
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: nuPrompt() Insert into Field?

Unread post by pmjd »

Ok, sounds good but not sure how to impliment that.

I've set an onclick to get the value of the Select object, and store it in a variable

Code: Select all

$status = nuGetValue('mpd_status',val);
I then tried to modify the nuPromptOnClose as follows:

Code: Select all

function nuOnPromptClose(val, ok) {
if (ok) {
     nuSetValue('mpd_reason', val);
    nuDisable('mpd_status')
}
else {nuSetValue('mpd_status', $status );}
}
But not quite working.
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: nuPrompt() Insert into Field?

Unread post by kev1n »

In the form's custom code:

Code: Select all

var status = nuGetValue('mpd_status');

and nuOnPromptClose():

Code: Select all

function nuOnPromptClose(val, ok) {
    if (ok) {
        nuSetValue('mpd_reason', val);
        nuDisable('mpd_status')
    } else {
        nuSetValue('mpd_status', status); 
    }
}
Post Reply