Page 1 of 1

Conditional Select fields before Save

Posted: Fri Feb 16, 2018 10:11 pm
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

Re: Conditional Select fields before Save

Posted: Fri Feb 16, 2018 11:34 pm
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

Re: Conditional Select fields before Save

Posted: Sat Feb 17, 2018 12:07 am
by tovidiu
Your method is better, I will try it with a onchange event.

Ovidiu

Re: Conditional Select fields before Save

Posted: Sat Feb 17, 2018 1:00 am
by tovidiu
Perfect.... it works!

Ovidiu

Re: Conditional Select fields before Save

Posted: Sat Feb 17, 2018 1:30 am
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

Re: Conditional Select fields before Save

Posted: Sat Feb 17, 2018 2:01 am
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