Page 1 of 1

[Solved] Set cursor in first field on screen to filled

Posted: Tue Oct 21, 2008 3:17 am
by Duketown
Hi,

During the building and testing of my modules, it disturbes me that whenever I open a new page I have to set the focus to the first field to be entered with the mouse.
Is there a code part that I can push in to my coding that tells the webpage to focus on the first field that I define.

Example: when I open up the admin login screen of a CMSMS website, the focus (the cursor) is on the username. I can start typing immediately. When I use, in the back end, Content, Pages, Edit page: home, I can't find the active field/button. I would expect it to be on the content type or title.
The same is true for the modules that I build.

So how to set the focus to the content type field.

Duketown
Using IE7
[Edit: Same situation in Google Chrome]

Re: Set cursor in first field on screen to filled

Posted: Tue Oct 21, 2008 9:25 am
by aln_cms
Hi Duketown,
I've never come across something like this in the API, it's a goo idea.  I wonder does CGExtensions provide this for CMSMS?

Alan

Re: Set cursor in first field on screen to filled

Posted: Wed Oct 22, 2008 7:30 am
by Russ
Use some Javascript to do it for you? Use tab index for the form fields (not so good)...

Re: Set cursor in first field on screen to filled

Posted: Wed Oct 22, 2008 8:37 pm
by Duketown
Is Javascript the only possible solution?
During development in whatever language I try to put in code to overcome RSI and to make it easy for the end user. Isn't this then a HTML problem?

Duketown

Re: Set cursor in first field on screen to filled

Posted: Thu Oct 23, 2008 5:30 am
by Duketown
Hi,

I did some research in the coding. It appears that in the login script the input field 'User name' gets the class="defaultfocus". In the themes directory there is /includes/standard.js (yes, the javascript that Russ is maybe referring to). Reading that script, you will come cross a function called defaultfocus(), which is called during the loading of a window (at least that is what I make of it).
Just above the function defaultfocus() is also some comment: //use
So I tried to change the template that I wanted to have the first field a focus on by changing its class:

Code: Select all

<p class="defaultfocus">{$inputname}</p>
in stead of

Code: Select all

<p class="pageinput">{$inputname}</p>
I see that the line up of the fields is changing (due to the css settings of pageinput I think), but no change on the focus to the field it self.

Now I did my change on the part and not on the part. So I had to remove 'class="defaultfocus"' from the template and into the input generation part. I changed the line in the connected program as follows:

Code: Select all

...assign('inputname', ...CreateInputText($id, 'name', $name, 40, 80, 'class="defaultfocus"'));
The , 'class="defaultfocus"' makes the difference ;D.

If it concerns a CreateInputDropdown field, you will not see the autofocus immediately, but using the tab key once will highlight the contents letting you know the field is in focus.

Duketown