Post by lev » Thu May 15, 2008 12:18 am

I love the OpenCart solution! I had one of several little pet peeves and it finally got to the point where I needed to get rid of it.. so:

When logging into the admin screen, the username field and password are displayed and a person can't help but want to just type the username, hit tab, type the password and press enter, but no focus is set. I added a little solution that focuses the username box and it should work for all browsers and no matter what you have customly added into your load events..

in /admin/template/{default}/content/login.tpl add the following code to the top of the page:

     *replace {default} with a different name if oyu have changed the template you are using for the admin store manager, else just use default without the {}

Code: Select all

<script type="text/javascript">
	addLoadEvent(setfocus);
    function setfocus() {
		var username = document.getElementsByName('username');
		if(username[0]){
			username[0].focus();
		}       
    }
	function addLoadEvent(func) {
  		var oldonload = window.onload;
  		if (typeof window.onload != 'function') {
    		window.onload = func;
  		} else {
	    	window.onload = function() {
	      	if (oldonload) {
	        	oldonload();
	      	}
	      	func();
	    	}
  		}
	}
</script>
Thats it :)
Last edited by lev on Thu May 15, 2008 12:23 am, edited 1 time in total.

lev
New member

Posts

Joined
Wed Apr 30, 2008 10:47 pm

Post by Kartoffelz » Sun May 18, 2008 9:37 pm

Nice little add-on. :)
Personally I also prefer having diverse JavaScript checks/save-guards through sections. Like checking if input fields (i.e.: admin username/password) are not blank, etc.
Once an error occurs it's always handy to focus the specific field where the error takes place.

New member

Posts

Joined
Fri Apr 04, 2008 10:44 pm
Location - The Netherlands

Post by bruce » Thu Jun 05, 2008 8:26 pm

Thanks lev!!

I have had the same peeve for some time and have put your code in my standard build for both the admin and catalog login.

cheers

Bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by lev » Sat Jun 14, 2008 3:40 am

My Pleasure Bruce  ;D

lev
New member

Posts

Joined
Wed Apr 30, 2008 10:47 pm

Post by hm2k » Thu Jun 26, 2008 7:27 pm

Why not just replace do this?

OPEN layout.html
FIND
REPLACE WITH
Last edited by hm2k on Fri Jun 27, 2008 4:39 pm, edited 1 time in total.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by lev » Fri Jun 27, 2008 10:34 pm

hm2k.. i know u are reputable here and probably much more versetile with php and the site, but let me explain why i believe your code is not the right way to do it...

You make several assumptions that can lead you into the dark:

You assume the cart and specifically the login form is the parent document, however it can be wrapped
You assume the user authentication form is the only form on that page
Tou assume that no other events are specified in the layout.tpl or anywhere else in the page being loaded.
You assume that all broswers are capable of traversing the DOM in the same manner which has bit in you know where before becuase they do differ.

However I may be wrong and it may work fine across it all... just wanted to make it bullet proof.

lev
New member

Posts

Joined
Wed Apr 30, 2008 10:47 pm

Post by hm2k » Sat Jun 28, 2008 12:02 am

Assumptions can be made when you KNOW for sure.

What I have proposed works with the supplied default template, you can change your own templates accordingly.

I don't see why you need to do it any differently.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by lev » Sat Jun 28, 2008 4:34 am

thanks for the constructive critisism ::) ;D ;)

lev
New member

Posts

Joined
Wed Apr 30, 2008 10:47 pm
Who is online

Users browsing this forum: No registered users and 3 guests