Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Conditional Select fields before Save

Questions related to using nuBuilder Forte.
Post Reply
tovidiu
Posts: 17
Joined: Sat Jan 06, 2018 5:45 pm

Conditional Select fields before Save

Unread post by tovidiu »

It is possible to use conditional select before saving the record ?

I have 3 tables 1) judet 2) terad 3) localit that are linked like this 3 -> 2 -> 1

Sql for localit Select is

Code: Select all

SELECT SIRUTA,NUMELOC FROM localit
WHERE SIRSUP = '#SIRSUP#'
Sql for terad Select is

Code: Select all

SELECT SIRSUP,NUMETERAD FROM terad
WHERE CODJUD = '#judet#'
Sql for judet Select is

Code: Select all

SELECT CODJUD,NUMEJUD FROM judet
It works if I save the record for every selection. The problem is that the new record is added with a lookup object and when I save a new record the popup is closing.
Thanks ,
Ovidiu
You do not have the required permissions to view the files attached to this post.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Conditional Select fields before Save

Unread post by admin »

Ovidiu,

Using hash cookies like #judet#, will only populate the Select as it loads. (returning from the server)

To rebuild a Select Object you need to go back to the server to get an updated list.

You can do this 2 ways.

1- The way you were doing it - saving the record.
2- Running a Hidden Procedure that will...
-Go back to the server.
-Ask a question.
-Return an answer with a new list for a Select Object - and some Javascript that will rebuild the Select Object.

http://wiki.nubuilder.net/nubuilderfort ... nPHPHidden
http://wiki.nubuilder.net/nubuilderfort ... ptCallback

If you would like an example, here is one we prepared earlier...

https://www.youtube.com/watch?v=ifbPhcvI5o8

This is the Procedure code...

Code: Select all

$a  = [];
$s  = "SELECT * FROM zzzzsys_translate WHERE trl_language = '#pick#'";
$t  = nuRunQuery($s);

while($r = db_fetch_object($t)){
    $a[]    = $r->trl_translation;
}

$j  = json_encode($a);

$js = "


get_phrases();

function get_phrases(){

    var p = $j;
    
    $('#phrases').empty();

    if(p != ''){

        for(var i = 0; i < p.length;i++){  
            $('#phrases').append('<option value=\"' + p[i] + '\">' + p[i] + '</option>'); 
        }
        
    }
    
}

";

nuJavascriptCallback($js);
Steven
tovidiu
Posts: 17
Joined: Sat Jan 06, 2018 5:45 pm

Re: Conditional Select fields before Save

Unread post by tovidiu »

Your method is better, I will try it with a onchange event.

Ovidiu
tovidiu
Posts: 17
Joined: Sat Jan 06, 2018 5:45 pm

Re: Conditional Select fields before Save

Unread post by tovidiu »

Perfect.... it works!

Ovidiu
tovidiu
Posts: 17
Joined: Sat Jan 06, 2018 5:45 pm

Re: Conditional Select fields before Save

Unread post by tovidiu »

Now I have 2 problems
1) I added a onchange event on judet to populate terad selection .... everything is ok but when I save the record it doesn't save selection in terad.
2) I added a second onchange event in terad to populate localit selection ..... it doesn't work only after I save de record and then is problem 1 again.
Its possible to add a onchange event to two fields ? Or I have to use onclick .

Note: terad and localit is a single selection.

Ovidiu
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Conditional Select fields before Save

Unread post by admin »

Ovidiu,

You said...
terad and localit is a single selection
These would work better (and without running a Procedure) with a Lookup.

This is because a Lookup DOES go back to the server to get a value or list to pick from.

Therefore using Hash Cookies in a Lookup's Form will work.

http://wiki.nubuilder.net/nubuilderfort ... b_-_Lookup
http://wiki.nubuilder.net/nubuilderfort ... Custom_SQL


Steven
Post Reply