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

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Duketown

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

Post 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]
Last edited by Duketown on Thu Oct 23, 2008 5:33 am, edited 1 time in total.
User avatar
aln_cms
Forum Members
Forum Members
Posts: 88
Joined: Mon Jan 08, 2007 7:09 pm
Location: Ireland

Re: Set cursor in first field on screen to filled

Post 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
--
Alan Ryan
Lead Developer
CodeCrunchers Internet Software Development - Ireland
http://www.codecrunchers.ie
Russ
Power Poster
Power Poster
Posts: 813
Joined: Fri Nov 25, 2005 5:02 pm
Location: North West England

Re: Set cursor in first field on screen to filled

Post by Russ »

Use some Javascript to do it for you? Use tab index for the form fields (not so good)...
Duketown

Re: Set cursor in first field on screen to filled

Post 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
Duketown

Re: Set cursor in first field on screen to filled

Post 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
Last edited by Duketown on Thu Oct 23, 2008 5:49 am, edited 1 time in total.
Post Reply

Return to “Developers Discussion”