nuPrompt() Insert into Field?

Questions related to customising nuBuilder Forte with JavaScript or PHP.

nuPrompt() Insert into Field?

Unread postby pmjd » Tue Sep 14, 2021 8:51 pm

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
pmjd
 
Posts: 76
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby kev1n » Tue Sep 14, 2021 9:57 pm

Use the nuOnPromptClose callback to retrieve the entered value and assign it to a field.
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby pmjd » Tue Sep 14, 2021 10:57 pm

The nuOnPromptClose shows how to set a nuMessage but been trying to use both nuSetValue and nuSetFormValue but neither seems to work
pmjd
 
Posts: 76
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby kev1n » Tue Sep 14, 2021 11:03 pm

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')
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby pmjd » Tue Sep 14, 2021 11:43 pm

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?
pmjd
 
Posts: 76
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby kev1n » Wed Sep 15, 2021 12:10 am

What value should "undo" set ?
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby pmjd » Wed Sep 15, 2021 12:29 am

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?
pmjd
 
Posts: 76
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby kev1n » Wed Sep 15, 2021 12:37 am

Couldn't you store the current select value in a variable and when cancel is chosen in nuPrompt, revert to that stored value?
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby pmjd » Wed Sep 15, 2021 1:16 am

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.
pmjd
 
Posts: 76
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Re: nuPrompt() Insert into Field?

Unread postby kev1n » Wed Sep 15, 2021 1:33 am

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);
    }
}
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Next

Return to Custom Code

Who is online

Users browsing this forum: No registered users and 6 guests

cron