Page 1 of 2
nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 1:21 pm
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
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 2:27 pm
by kev1n
Use the
nuOnPromptClose callback to retrieve the entered value and assign it to a field.
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 3:27 pm
by pmjd
The nuOnPromptClose shows how to set a nuMessage but been trying to use both nuSetValue and nuSetFormValue but neither seems to work
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 3:33 pm
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')
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 4:13 pm
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?
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 4:40 pm
by kev1n
What value should "undo" set ?
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 4:59 pm
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?
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 5:07 pm
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?
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 5:46 pm
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.
Re: nuPrompt() Insert into Field?
Posted: Tue Sep 14, 2021 6:03 pm
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);
}
}