Conditional Select fields before Save

Questions related to using nuBuilder Forte.

Conditional Select fields before Save

Postby tovidiu » Sat Feb 17, 2018 6:41 am

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
Attachments
ex_select.png
ex
ex_select.png (5.41 KiB) Viewed 1165 times
tovidiu
 
Posts: 17
Joined: Sun Jan 07, 2018 2:15 am

Re: Conditional Select fields before Save

Postby admin » Sat Feb 17, 2018 8:04 am

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/nubuilderforte/index.php/Javascript#nuRunPHPHidden
http://wiki.nubuilder.net/nubuilderforte/index.php/PHP#nuJavascriptCallback

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
admin
Site Admin
 
Posts: 3289
Joined: Mon Jun 15, 2009 9:53 am

Re: Conditional Select fields before Save

Postby tovidiu » Sat Feb 17, 2018 8:37 am

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

Ovidiu
tovidiu
 
Posts: 17
Joined: Sun Jan 07, 2018 2:15 am

Re: Conditional Select fields before Save

Postby tovidiu » Sat Feb 17, 2018 9:30 am

Perfect.... it works!

Ovidiu
tovidiu
 
Posts: 17
Joined: Sun Jan 07, 2018 2:15 am

Re: Conditional Select fields before Save

Postby tovidiu » Sat Feb 17, 2018 10:00 am

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
tovidiu
 
Posts: 17
Joined: Sun Jan 07, 2018 2:15 am

Re: Conditional Select fields before Save

Postby admin » Sat Feb 17, 2018 10:31 am

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/nubuilderforte/index.php/Objects#Tab_-_Lookup
http://wiki.nubuilder.net/nubuilderforte/index.php/Hash_Cookies#Custom_SQL


Steven
admin
Site Admin
 
Posts: 3289
Joined: Mon Jun 15, 2009 9:53 am


Return to General



cron