Show drop-down list when entering a non-existent item

Goal:
  • A user can get a dropdown list, just by typing a few letters and pressing enter. (Instead of entering a * to trigger the drop down list or instead of using the mouse)

Solution:

  • The following static method can be called from the overridden task method of any form. The current implementation only supports ItemId and RouteOpr field. (It would be great if this code were generalized by someone.)
  • NOTE: relies on field name

//bw start
//Changed on 16 Jul 2007 by TW
/* Description:
display dropdown list if enter clicked while an itemid is not valid
*/
static public int task(Args args, int _taskId)
{
    #MACROLIB.Task //import task macro
    FormControl fc;
    FormStringControl fsc;

    switch(_taskId)
    {
        case #taskEnter: //enter key pressed
            fc = args.caller().selectedControl();
            if (SysFormRun::controlType(classidget(fc)) == FormControlType::String)
            {
                fsc = fc;

                if (fsc.name() like "*" + fieldid2name(tablenum(InventTable),fieldnum(InventTable,ItemId)) + "*")
                { //ItemId fields
                    if (!InventTable::exist(fsc.text()))
                    {
                        fsc.lookup();
                        return 1;
                    }
                }
                else if (fsc.name() like "*" + fieldid2name(tablenum(InventTable),fieldnum(Route,OprId)) + "*")
                { //RouteOpr Fields
                    if (!RouteOprTable::exist(fsc.text()))
                    {
                        fsc.lookup();
                        return 1;
                    }
                }
            }
            break;
    }
    return 0;
}
//bw end