Page 1 of 1
Open different forms according to value in browse forms
Posted: Wed Apr 02, 2025 3:07 am
by Lala
Hi, I have a browse form which shows patient number, name, and which treatment round they are on (Treatment Round 1, Treatment Round 2, Treatment Round 3, or Treatment Round 4.
I have four edit forms for use according to which Treatment Round the patient is on - TXR1, TXR2, TXR3 and TXR4.
I want to click on a record in the browse form and redirect to open the right form (with the correct patient details). How do I do this?
Re: Open different forms according to value in browse forms
Posted: Wed Apr 02, 2025 3:14 am
by kev1n
Hi,
Take a look at
nuSelectBrowse()
This forum post also might be useful to retrieve a value of the clicked row.
Then you can create a function like the one below to check the selected patient's Treatment Round and open the corresponding edit form.
Replace **TXR1, TXR2, TXR3, or TXR4** with the corresponding form IDs.
Code: Select all
function nuSelectBrowse(event, element) {
const row = $('#' + event.target.id).attr('data-nu-row');
const treatmentRound = $('#nucell_' + row + "_2").html(); // e.g. the Treatment Round is in column 3.
let formId = '';
switch (treatmentRound) {
case 'Treatment Round 1':
formId = 'TXR1';
break;
case 'Treatment Round 2':
formId = 'TXR2';
break;
case 'Treatment Round 3':
formId = 'TXR3';
break;
case 'Treatment Round 4':
formId = 'TXR4';
break;
default:
alert('No matching form found for this treatment round.');
return;
}
const primaryKey = $(element).attr('data-nu-primary-key');
nuForm(formId, primaryKey, '', '', '2');
}
Explanation
- The function retrieves the selected record’s row index.
- It extracts the values from the browse form, including the Treatment Round.
- Based on the Treatment Round, it assigns the correct edit form (TXR1, TXR2, etc.).
- It then opens the corresponding form using nuForm().
Re: Open different forms according to value in browse forms
Posted: Thu Apr 03, 2025 12:55 am
by Lala
And once again, you are a life saver! Thank you!!!
Re: Open different forms according to value in browse forms
Posted: Thu Apr 03, 2025 1:52 am
by Lala
Hi, I am getting an error message saying 'Error loading the form'. I put the code below in the custom code of the browse form where PTTX1ED is the id of the form to load.
Code: Select all
function nuSelectBrowse(event, element) {
const row = $('#' + event.target.id).attr('data-nu-row');
const treatmentRound = $('#nucell_' + row + "_2").html(); // e.g. the Treatment Round is in column 3.
let formId = '';
switch (treatmentRound) {
case 'Treatment Round 1':
formId = 'PTTX1ED';
break;
case 'Treatment Round 2':
formId = 'PTTX2ED';
break;
case 'Treatment Round 3':
formId = 'PTTX3ED';
break;
case 'Treatment Round 4':
formId = 'PTTX4ED';
break;
default:
alert('No matching form found for this treatment round.');
return;
}
const primaryKey = $(element).attr('data-nu-primary-key');
nuForm(formId, primaryKey, '', '', '2');
}
Re: Open different forms according to value in browse forms
Posted: Thu Apr 03, 2025 4:07 am
by kev1n
PTTX1ED seems to be the form code, not id (primary key)
Check out the documentation:
https://wiki.nubuilder.cloud/index.php? ... ipt#nuForm