Wet-boew: Form validation: Error anchor, label hidden when focus

Created on 20 Jul 2017  路  4Comments  路  Source: wet-boew/wet-boew

When you validate a form, you get the list of errors at the top and if you click on a link to bring you to the form field that is related to the error, the focus is in the field but you scroll past the label that's above the field.

Click on this link
image

Brings you to this field
image

@stdgit has created a script that scrolls the window up a few pixels/ Could we add something like this in WET?

P.S. @RobJohnston, I checked the open tickets and didn't find one on this issue. Thought you should know!

Form Validation Second opinion Bug Feature Request Normal Usability

Most helpful comment

@shawnthompson , I agree ;-) I don't remember reading this one before and my search of the wet-boew and gcweb repos found nothing.

All 4 comments

@shawnthompson , I agree ;-) I don't remember reading this one before and my search of the wet-boew and gcweb repos found nothing.

I am sure that is possible to add a scrolling feature that scrolls the window up a few pixels.

Some test would need to be done to ensure the focus order (WCAG 2.4.3) remains the same after scrolling.

@StdGit could you paste share your solution with us and we can try to incorporate it into WET?

Here it is

I did it for all anchor with a #hash but you can do it specifically for the ones with an error class

$(document).on("wb-ready.wb",function () {

    //To display the label after an error
    // Captures click events of all <a> elements with href starting with #
    $(document).on('click', 'a[href^="#"]', function (event) {
        window.setTimeout(function () {
            offsetAnchor();
        }, 0);
    });

    // The function actually applying the offset
    function offsetAnchor() {
        if (location.hash.length !== 0) {
            window.scrollBy(0,-80);
        }
    }

});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jkshapiro picture jkshapiro  路  6Comments

zomby22 picture zomby22  路  5Comments

swapnalithakarpspc picture swapnalithakarpspc  路  5Comments

nickmarcil picture nickmarcil  路  5Comments

AtomicNumber28 picture AtomicNumber28  路  7Comments