Not able to shift focus to Shipment Nbr field on Shipments screen

末鹿安然 提交于 2020-01-17 06:53:35

问题


I'm using the built in Acumatica browser commands to insert a new shipment record by pressing a function key. The function Key triggers the command with px.searchFrame(window.top,"main")['px_alls'].ds.executeCommand("Insert"); For some reason, it triggers the insert command, but it doesn't shift the focus to the Shipment Nbr input field. Also, if you try to shift the focus manually using var field=px_alls["edShipmentNbr"]; field.focus(); that doesn't work either. I've been able to shift the focus to other fields, so I know the code is correct, but I can't figure out why the focus can't be shifted to the Shipment Nbr input. Any ideas on what else can be done? It's not just the Insert command either. Calling the Cancel command, which should shift the focus, doesn't work either.

What's strange is that the Insert command can be called by pressing Ctrl+Insert, and it works perfectly.

I built some code that shifts the focus to the ship date field and then tabs backwards 5 times, which emulates correctly what the insert command should do, but it only works intermittently on the client's computer.

Thanks


回答1:


The Acumatica Framework provides built-in support for keyboard shortcuts via the following properties defined in PXButtonAttribute:

  • ShortcutShift = true/false : Determines Shift key presence
  • ShortcutCtrl = true/false : Determines Control key presence
  • ShortcutChar = ‘x’ : Determines shortcut character

Below is the sample to insert new Shipment when the user presses F2. Since the code snippet below utilizes capabilities of the framework, by pressing F2 the user executes the Insert command from the SOShipmentEntry BLC instead of simulating button click in JavaScript. This approach guarantees that all logic embedded into the Insert command, including setting focus to the Shipment Nbr input, is properly executed.

public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
    public class PXInsertShortCut<TNode> : PXInsert<TNode> 
        where TNode : class, IBqlTable, new()
    {
        public PXInsertShortCut(PXGraph graph, string name)
        : base(graph, name)
        {
        }
        public PXInsertShortCut(PXGraph graph, Delegate handler)
            : base(graph, handler)
        {
        }
        [PXUIField(DisplayName = ActionsMessages.Insert, MapEnableRights = PXCacheRights.Insert, MapViewRights = PXCacheRights.Insert)]
        [PXInsertButton(ShortcutChar = (char)113)]
        protected override IEnumerable Handler(PXAdapter adapter)
        {
            return base.Handler(adapter);
        }
    }

    public PXInsertShortCut<SOShipment> Insert;
}



回答2:


If you're executing a callback to the server in JavaScript, the callback return might set focus to another field after it finishes execution. Your focus() statement works but the callback return performs another focus() on a different control after yours.

Hooking the Ajax callback allows you to put your focus() statement after the Acumatica framework focus():

window.addEventListener('load', function () { px_callback.addHandler(ActionCallback); });

function ActionCallback(callbackContext) {
   px_alls["edShipmentNbr"].focus();
};


来源:https://stackoverflow.com/questions/43455496/not-able-to-shift-focus-to-shipment-nbr-field-on-shipments-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!