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.
Set Select Object Initial value before nuRefreshObject nuOnLoad
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
Strange, I don't get that error at all in nuDebug.
However I just checked nuDebug again after recreating the forms and I found a bunch of other errors relating to a typo in the SQL in frmT3 > t1_description.
I have fixed the typo and fixed the PHP (I think it ended up there by accident when I was trying to make it work), now there are no errors but the behavior is still the same. I have attached the frmT3 dump file with the amendments.
If I keep refreshing, I can see the correct value in t2_id flashing and then disappearing. So somehow it is getting set, but then it is cleared.
However I just checked nuDebug again after recreating the forms and I found a bunch of other errors relating to a typo in the SQL in frmT3 > t1_description.
I have fixed the typo and fixed the PHP (I think it ended up there by accident when I was trying to make it work), now there are no errors but the behavior is still the same. I have attached the frmT3 dump file with the amendments.
If I keep refreshing, I can see the correct value in t2_id flashing and then disappearing. So somehow it is getting set, but then it is cleared.
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 4297
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
Is it correct that the value for t1 has to be set only for existing records (not new ones) ?
The behaviour of nuRefreshObject() is that the select's options are refreshed and blank value is set.
The behaviour of nuRefreshObject() is that the select's options are refreshed and blank value is set.
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
Yes, so if it is a new record the value for t1 does not get set. I guess if it gets no records then set it to nothing shouldn't cause any problems.
Unfortunately nuRefreshObject() does not seem to be clearing the value, I use it on another form to split the value and label that was concatenated with '|'.
I think this is happening at the start of the form load because the value of t1 is empty.
Then t1 to updates, and then nuRefresh t2 updates the option list. But the value remains blank.
I just tried to remove all the nuRefresh and t2 remains blank, and has no options to select.
I have a feeling that the value of t1 is being assigned after t2 runs its Select SQL to generate its list.
Is there any way to assign a value to t1 using PHP without js? Maybe if we can set the HTML selected attribute (selected="selected ")?
Unfortunately nuRefreshObject() does not seem to be clearing the value, I use it on another form to split the value and label that was concatenated with '|'.
I think this is happening at the start of the form load because the value of t1 is empty.
Then t1 to updates, and then nuRefresh t2 updates the option list. But the value remains blank.
I just tried to remove all the nuRefresh and t2 remains blank, and has no options to select.
I have a feeling that the value of t1 is being assigned after t2 runs its Select SQL to generate its list.
Is there any way to assign a value to t1 using PHP without js? Maybe if we can set the HTML selected attribute (selected="selected ")?
-
- nuBuilder Team
- Posts: 4297
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
I'll answer later as I have no access to my computer right now
-
- nuBuilder Team
- Posts: 4297
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
When t2_id is refreshed, the query
retrieves all records from tblT2 that match #t1_id#. nuRefreshDisplayObject() runs the query and preselects the empty option.
What I don't really understand is why you are not storing the values of the select objects in the form's table (tblT3) directly.
Code: Select all
SELECT
tblT2.tblT2_id,
CONCAT(COALESCE(tblT2.t2_name,''),'|',COALESCE(tblT2.t3_label,''))
FROM
tblT2
WHERE
((tblT2.t1_id = '#t1_id#'))
What I don't really understand is why you are not storing the values of the select objects in the form's table (tblT3) directly.
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
Yes, that is correct.
I am doing it in separate tables so that these values on not repeated over and over again, and makes it impossible for someone to type in different text and make mistakes for what should really be the same value. In an existing system I have some of these tiers entered 4 or 5 different words / spellings which makes it hard to filter / manage. These values can only be added / edited by administrators to avoid multiple texts of the same value. Also makes the UI easier to use because there are drop downs. I also don't want to hard code these values, because no one on my team will know how to add / change values.
It also allows me to add more tiers in the future if I need to without too much hassle. I can also modify the tiers like this easily.
It means that I have fixed IDs for each tier category that will be critical further on in the DB design.
Isn't there any way to assign the t1_value with pure PHP? I have been racking my brain with this. But I think using nuAddJavascript to assign this value is happening to late for the SQL in t2_id to return a valid list so that the value in the table is on that list.
I am doing it in separate tables so that these values on not repeated over and over again, and makes it impossible for someone to type in different text and make mistakes for what should really be the same value. In an existing system I have some of these tiers entered 4 or 5 different words / spellings which makes it hard to filter / manage. These values can only be added / edited by administrators to avoid multiple texts of the same value. Also makes the UI easier to use because there are drop downs. I also don't want to hard code these values, because no one on my team will know how to add / change values.
It also allows me to add more tiers in the future if I need to without too much hassle. I can also modify the tiers like this easily.
It means that I have fixed IDs for each tier category that will be critical further on in the DB design.
Isn't there any way to assign the t1_value with pure PHP? I have been racking my brain with this. But I think using nuAddJavascript to assign this value is happening to late for the SQL in t2_id to return a valid list so that the value in the table is on that list.
-
- nuBuilder Team
- Posts: 4297
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
If you store just the ids (not the text) in tblT3 you won't encounter that problem since the text is retrieved from the other tables.
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
Oh, I get what you mean now. Hmmm, I did not think of that.
Sorry my background is really in Microcontrollers, so bean counting is second nature to me
Let me give it a go this weekend and see if it works. Thanks for your advise and help.
Sorry my background is really in Microcontrollers, so bean counting is second nature to me

Let me give it a go this weekend and see if it works. Thanks for your advise and help.
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
I did some testing and it seems that doing it with each of the previous IDs stored in the consequent, I found that you can run into some problematic situations if someone tries to change something in one of the middle tier tables and end up with conflicting data. So I ended only keeping the ID from the previous tier table. To keep each preceding tier id in each consequent table will need some data validation, which I couldn't figure out. My final solution was to run the SQL in PHP, store it in a JS variable, and deal with it in JS after the form loads and the Select Objects Refreshes. Maybe not pretty but it works.
Edit Code:
Before Edit Code:
This seems to work well, but I want to try and centralize the JS object that deals with this to reduce the amount of code needed on both ends.
Is there a place to put global JS objects / functions if I wanted to implement them in multiple different locations?
Edit Code:
Code: Select all
t1_id_Available = false;
t1_id_Loaded = false;
t2_id_Available = false;
t2_id_Loaded = false;
function nuOnLoad() { // Run on Load
nuRefreshSelectObject('t1_id'); // Refresh the first tier to solve the concatenation
var f = nuCurrentProperties(); // Collect the Form Properties
if (nuFormType() == 'edit') { // Check if the form is in edit mode
if (f.title == 'Fast Form Tier 3') { // Confirm we are using the correct form
if(typeof init_t1_id !== 'undefined'){ // Check if variable exists
if (init_t1_id !== null){ // Check if variable is not null
t1_id_Available = true;
}
}
if(typeof init_t2_id !== 'undefined'){ // Check if variable exists
if (init_t2_id !== null){ // Check if variable is not null
t2_id_Available = true;
}
}
}
}
}
//On Select Object Refresh
function nuSelectObjectRefreshed(formId, selectId, count) {
//alert(selectId);
if(selectId == 't1_id'){
if( (t1_id_Available == true) && (t1_id_Loaded == false) ) {
document.getElementById('t1_id').value = init_t1_id;
t1_id_Loaded = true;
nuRefreshSelectObject('t2_id');
}
}
if(selectId == 't2_id'){
if( (t2_id_Available == true) && (t2_id_Loaded == false) ) {
document.getElementById('t2_id').value = init_t2_id;
t2_id_Loaded == true;
}
}
}
Code: Select all
//Run a query to determined the Tier1 ID based on the value stored in t2_id.
$strQry_t1_id = "SELECT tblT1_id FROM tblT1 JOIN tblT2 ON t1_id = tblT1_id JOIN tblT3 ON t2_id = tblT2_id WHERE tblT3_id = '#RECORD_ID#'";
$strQry_t2_id = "SELECT t2_id FROM tblT3 WHERE tblT3_id = '#RECORD_ID#'";
$tblQry_t1_id = nuRunQuery($strQry_t1_id);
$tblQry_t2_id = nuRunQuery($strQry_t2_id);
//Check to see if we have one row from the query
if (db_num_rows($tblQry_t1_id) == 1) {
$recQry_t1_id = db_fetch_object($tblQry_t1_id);
// Add javascript to update the t1_id Select Object's value
$strJSvars = "var init_t1_id = '$recQry_t1_id->tblT1_id';";
} else {
$strJSvars = "var init_t1_id = null;";
}
//Check to see if we have one row from the query
if (db_num_rows($tblQry_t2_id) == 1) {
$recQry_t2_id = db_fetch_object($tblQry_t2_id);
// Add javascript to update the t1_id Select Object's value
$strJSvars .= "var init_t2_id = '$recQry_t2_id->t2_id';";
} else {
$strJSvars .= "var init_t2_id = null;";
}
nuAddJavascript($strJSvars);
Is there a place to put global JS objects / functions if I wanted to implement them in multiple different locations?
-
- nuBuilder Team
- Posts: 4297
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Set Select Object Initial value before nuRefreshObject nuOnLoad
JS functions that are added in Setup -> Header will be available anytime within nuBuilder.