Cant scroll with Javascript

1
Hey all, We have a page setup with a 4 step wizard; each step acts like its own page but everything is all on one page. When the user goes to the next step, the page doesn't refresh, so the scroll stays where they were when they clicked "continue" near the bottom. I have tried using the "ScrollToAnchor" widget, but the events offered don't really work for "scroll to the top when the next step is displayed", and any custom Javascript that I have written for this in an "HTMLSnippet" widget seems to execute, but when I used click events it appears that they do not get applied to the Mendix buttons. I even went so far as to create my own buttons in an "HTMLSnippet" widget, but my click events wouldn't fire.   Is there a way to scroll to the top of the page when a user clicks a Mendix button?
asked
2 answers
3

You need to use the dojo/window library and specifically the function ScrollIntoView. See: https://dojotoolkit.org/api/?qs=1.7/dojo/window

An implementation of this can be found in the FocusOnErrorWidget. The part were it is used is:

                        // Scroll element into view
                        win.scrollIntoView(node);
                        // Find any input or select elements in the node and set the focus if found.
                        // (Note that an error could be displayed on a read only element.)
                        inputNodeList = domQuery('input, select', node);
                        if (inputNodeList.length > 0) {
                            inputNodeList[0].focus();
                        }

Here, 'win' is a reference to 'dojo/window'.

Good luck!

answered
1

The code you can use inside the snippet:

require(["dojo/window"], function(win){
  // here comes your JS code. References to the window library can be made like: win.scrollIntoView
});
answered