Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Application Development » How to provide choices for two compound foreign keys in a form? (I want to provide a selection mechanism such that fill two fields in a form can be chosen and populated.)
How to provide choices for two compound foreign keys in a form? [message #4853] Tue, 21 July 2015 21:15 Go to next message
rafs is currently offline  rafs
Messages: 69
Registered: May 2015
Member
I have a list1 for families, a list1 for variants.
I have a link1 from families to variants; and a link1 from variants to families.
families --< families_variants >-- variants
famiilies_variants only has (family_name, variant_name) as PK, with each field also being a FK to the parent tables.
This part is working fine.

Now, I have a table called lines, and a line is has a compound foreign key linking it to families_variants.
So,

lines
-----
line_id
line_text
...
family_name
variant_name

The question is, when filling in the New 'line' form, how to best go about providing the user with a method to select a combination of (family_name, variant_name) from the available entries in families_variants?
It would be good to allow them to choose a family_name, and then choose the available variant_names, or (bonus) if they could choose variant_name first, then choose the available families.


Re: How to provide choices for two compound foreign keys in a form? [message #4854 is a reply to message #4853] Wed, 22 July 2015 06:30 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
You can use a popup button. You can jump to a popup2 which will show the family name as the parent and family variants as the child. Upon entry you can detect that no family name has been chosen, so you can jump automatically to a popup1 whuch will show a list of family names and allow the user to pick one. This will then return to the popup2 which will be able to show the variants for the selected name.

Re: How to provide choices for two compound foreign keys in a form? [message #4855 is a reply to message #4853] Wed, 22 July 2015 10:14 Go to previous messageGo to next message
rafs is currently offline  rafs
Messages: 69
Registered: May 2015
Member
In my families field I have a popup1 and it fills the families textbox. fine.
In my variants field I have a popup2, but it complains that no parent is selected.
How do I get the popup1 to automatically start from the popup2?

Thanks.
Re: How to provide choices for two compound foreign keys in a form? [message #4856 is a reply to message #4855] Thu, 23 July 2015 07:18 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
This is what I have in the _cm_initialise() method of the parent entity in the POPUP2 task:
$pattern_id = getPatternId();
if (!preg_match('/order_id=/i', $where)) {
    if (isset($GLOBALS['return_from'])) {
        if ($GLOBALS['return_from'] == 'ord_order_header_p(popup1)') {
            // nothing selected from popup screen, so exit now
            scriptPrevious($GLOBALS['errors']);
        } // if
    } // if
    if (preg_match('/popup2/i', $pattern_id)) {
        // order_id has not been supplied yet, so get it now via a popup
        scriptNext('ord_order_header_p(popup1)', $where);
    } // if
} // if

It is expecting to find "order_id=...." in the $where string. If it isn't there it suspends the current task and executes the popup which will provide a value for order_id. If this popup is terminated without choosing a value then this task will quit and return to the task which called it.


Re: How to provide choices for two compound foreign keys in a form? [message #4938 is a reply to message #4856] Wed, 26 August 2015 22:14 Go to previous messageGo to next message
rafs is currently offline  rafs
Messages: 69
Registered: May 2015
Member
families --< families_variants >-- variants
family_name  family_name           variant_name
...          variant_name          ...

families_variants --< lines
                      line_id
                      family_name
                      variant_name


In the new 'lines' form, both popups now work. popup1 for "Family Name" field works, but popup2 families_variants (which does a popup1 for families first) then correctly gets the child value, and returns. It overwrites whatever was chosen previously in the "Family Name" field.

When "Family Name" (parent) is selected beforehand, then I want the "Variant Name" (popup2) to skip the launch of the popup1 (to choose the parent (family) again. This is the case #1 you describe here:
http://www.tonymarston.net/php-mysql/infrastructure-faq.html #faq79

Why doesn't the popup2 see that the parent has already been selected?

Thanks.
Re: How to provide choices for two compound foreign keys in a form? [message #4939 is a reply to message #4938] Thu, 27 August 2015 05:47 Go to previous message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
You need to look at the code in the _cm_initialise() method of the parent entity in the POPUP2 task. If the $where string contains something that identifies an entry on that table then continue, otherwise jump to a POPUP1 task to allow the user to select an entry.

This means that when calling the POPUP2 task and you already have a value for the parent entity which you want to use then this value must be included in the $where string which is passed to the POPUP2 task.


Previous Topic: Compound foreign keys in linking tables
Next Topic: ERROR: 22P02: invalid input syntax for integer
Goto Forum:
  


Current Time: Sat Nov 23 03:14:42 EST 2024

Total time taken to generate the page: 0.05923 seconds