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?
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Open different forms according to value in browse forms
-
- nuBuilder Team
- Posts: 4242
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 68 times
- Been thanked: 422 times
- Contact:
Re: Open different forms according to value in browse forms
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.
Explanation
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
And once again, you are a life saver! Thank you!!!
Re: Open different forms according to value in browse forms
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');
}
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 4242
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 68 times
- Been thanked: 422 times
- Contact:
Re: Open different forms according to value in browse forms
PTTX1ED seems to be the form code, not id (primary key)
Check out the documentation:
https://wiki.nubuilder.cloud/index.php? ... ipt#nuForm
Check out the documentation:
https://wiki.nubuilder.cloud/index.php? ... ipt#nuForm