Liferay/AlloyUI: Overriding util.js or disabling scrolling on form focus

360 Views Asked by At

How can I override (or hook) the function Liferay.Util.focusFormField in Liferay 7.0?

The method is defined in frontend-js-aui-web (portal-src\modules\apps\foundation\frontend-js\frontend-js-aui-web\src\main\resources\META-INF\resources\liferay\util.js).

The only way I could think of is to just overwrite it somewhere in a js-file, like so:

Liferay.Util.focusFormField = function(el) {
    var doc = $(document);

    var interacting = false;

    el = Util.getDOM(el);

    el = $(el);

    doc.on(
        'click.focusFormField',
        function (event) {
            interacting = true;

            doc.off('click.focusFormField');
        }
    );

    if (!interacting && Util.inBrowserView(el)) {
        var form = el.closest('form');

        var focusable = !el.is(':disabled') && !el.is(':hidden') && !el.parents(':disabled').length;

        if (!form.length || focusable) {
            el.focus(false); // modified
        }
        else {
            var portletName = form.data('fm-namespace');

            Liferay.once(
                portletName + 'formReady',
                function () {
                    el.focus(false); // modified
                }
            );
        }
    }
}

All I actually want is to disable the scrolling that happens whenever a form is submitted.

Does someone know what to do best to achieve this?

Another thing I found on the web is this: https://alloyui.com/api/files/alloy-ui_src_aui-form-validator_js_aui-form-validator.js.html#l216

But I cannot find it in liferay-7.0-source-files and no explanation how to override it.

0

There are 0 best solutions below