:: Forum >>

Scroll into view with an onfocus event?

Hi folks

This may be asking too much, but I'll have a go ....

I have a one line grid that I use as a form and in the grid cells I have AW.UI.Input elements. This number of elements is such that the user has to scroll across to complete all form elements (not great user interface design I know, but that's just how it is on this one).

I am using a validation toolkit (fValidate) that, after alerting an input value error returns focus to the offending input element for the user to correct. If the offending element is out of view, I would like the grid to be able to scroll automatically as the element receives focus from the validation tool, so that it is in view for the user.

I can see the methods setScrollLeft and setScrollTop so I figure that I might be able to set an onfocus event handler (using setEvent) for each of the inputs so that when they receive focus the grid would be scrolled to a given position. There are two further considerations, however:

a. I have tried a basic test :
input_element.setEvent("onfocus",function(event){alert("onfocus event happening")});
but cannot seem to get anything from this...
(when viewing rendered source I see that each input element has the attribute: onfocus="AW(this, event)", so this maybe overriding what I am trying to do??)
b. even if I can get the above working I think I would need to be able to distinguish between focus obtained by the user (keyboard or mouse) and focus obtained by the validation tool. Not sure if this is possible?

Any thoughts on this much appreciated
Many thanks,
Will
Will
Monday, December 19, 2005
Will, in your previous post:
/javascript.forum.9814.1/problem-using-setattribute-on-aw.html
you've got the right answer, so try doing same here :
input_element.getContent("box/text").setEvent("onfocus",function(event){alert("onfocus event happening")});
It worked for me with an onkeydown-event (when Enter key pressed) sets the focus on next Input).
Carlos
Monday, December 19, 2005
Thanks Carlos, you are right - I keep forgetting the 'getContent' bit!!

While this does set an onfocus event, it also seems to interfere with the Input element, in that it no longer accepts the user dragging the mouse across its content or using shift + arrow keys to highlight the content (e.g. for deletion).

Also as mentioned in my post I really would need a way of distinguishing focus that happens from user or otherwise. Any thoughts on this?

Maybe this is not a great road to go down......

Will
Will
Monday, December 19, 2005
You can try with:
.getContent('box/text').element().focus();

But...What if focus is set due a valid-fail (auto) and the user click on it after that?
(user manual-focus = supposed a correct-validation).
Maybe it is better to switch a variable to control if last validation-process was passed or not (onblur/button-click ??), an then set the focus conditionally.
Thanks
Carlos
Monday, December 19, 2005

This topic is archived.


Back to support forum

Forum search