Page 1 of 1

Populate a select tag with dynamic values or from table

Posted: Thu May 13, 2021 4:42 pm
by DMS

Hi there, how to populate a select tag with no fixed value or from table?
I mean, for example, i would like populate the select tag from current year to next 10 years.
Have you any idea?

Thanks in advance
Joe


Re: populate a select tag with no fixed value or from table

Posted: Thu May 13, 2021 8:53 pm
by arbei

You may see Server Events and Client Scripts -> Server Events -> Table-Specific -> Common -> Lookup_Selecting -> Example 4 in the help file. (v2021)


Re: populate a select tag with no fixed value or from table

Posted: Fri May 14, 2021 10:08 am
by mobhar

In order to implement setOptions method for Lookup object, then you have to enable Use lookup table, after that, you have to setup the Lookup Table by selecting the Table name, Link field, and at least Display field #1.

In addition, make sure you have already disabled Use modal dialog for lookup.

I have just tested this from the demo project for products table. I setup the SupplierID field just like I mentioned above, and then I put this code in Lookup_Selecting server event of the products table:

    if ($fld->Name == "SupplierID")
        $fld->Lookup->setOptions([
            ["link1", "display value 1", "", "", ""],
            ["link2", "display value 2", "", "", ""],
            ["link3", "display value 3", "", "", ""],
            ["link4", "display value 4", "", "", ""]
        ]); // Use static array

And it works properly. The static option is now displayed as expected.

The conclusion is, since you are using setOptions method that belongs to the Lookup object, then you are still having to setup the Lookup Table as usual.


Re: populate a select tag with no fixed value or from table

Posted: Fri Sep 03, 2021 10:37 am
by arbei

Also work for User Values. (v2022)


Re: populate a select tag with no fixed value or from table

Posted: Sat Sep 04, 2021 8:12 am
by mobhar

Great. Thanks for the info. This is one of the improvements I like from v2022.