Page 1 of 2

Automatically erasing search box text

Posted: Wed Jan 24, 2007 11:27 pm
by moorezilla
Someone asked me to make the search box automatically erase the prepopulated text when someone clicks into it. I couldn't figure out how to do it with the existing module tags, so I added the following hack to action.default.php

On line 28 of action.default.php I added:

$dis = "onfocus=\"if(this.value==this.defaultValue) this.value='';\"";

and to line 33 I added the variable $dis to the end:

$this->smarty->assign('inputbox', $this->CreateInputText($id, 'searchinput', $searchtext, 20, 50, $dis));


This probably isn't the best way to do it, but it worked for me, so I'm passing it along. If anyone has a better way, please let me know. Otherwise, if you need it, enjoy.

Re: Automatically erasing search box text

Posted: Thu Jan 25, 2007 12:05 pm
by cyberman
Like this one - will be my default for future :) ...

Re: Automatically erasing search box text

Posted: Thu Jan 25, 2007 12:27 pm
by moorezilla
Maybe this could be rolled into the Search module as a default action?

I can't think of any situations where one wouldn't want the search text box to operate this way.

Re: Automatically erasing search box text

Posted: Thu Jan 25, 2007 5:17 pm
by british.assassin
nice one, thanks .... i was trying to figure out how to do this myself

Re: Automatically erasing search box text

Posted: Thu Jan 25, 2007 6:16 pm
by moorezilla
No problem, Bond. No problem.

Re: Automatically erasing search box text

Posted: Wed Jan 31, 2007 3:46 pm
by liquid
Wonderful, thank you!

Re: Automatically erasing search box text

Posted: Wed Feb 07, 2007 10:50 pm
by tsw
create new feature request in forge

Re: Automatically erasing search box text

Posted: Thu Feb 08, 2007 4:42 am
by askme
I am new to CMSMadeSimple..
But where is this file action.default.php is located? Which folder, subfolder of CMSmadeSimple

Re: Automatically erasing search box text

Posted: Fri Feb 16, 2007 6:43 pm
by webform
moorezilla wrote: On line 28 of action.default.php I added:

$dis = "onfocus="if(this.value==this.defaultValue) this.value='';"";
To extend it a little so it falls back to default if the user leave the searchbox without searching:

$dis = "onfocus="if(this.value==this.defaultValue) this.value='';""." onBlur="if(this.value=='') this.value=this.defaultValue;"";

Re: Automatically erasing search box text

Posted: Fri Feb 16, 2007 8:14 pm
by Elijah Lofgren
I think I'll try getting this into the core. :)

Re: Automatically erasing search box text

Posted: Fri Feb 16, 2007 9:25 pm
by moorezilla
Nice.

If you use a variable, my Rhodesian Ridgeback insists that you use "hogan" in his honor.

Re: Automatically erasing search box text

Posted: Sat Feb 17, 2007 3:02 am
by Elijah Lofgren
Applied: http://viewsvn.cmsmadesimple.org/viewsv ... w=rev  :)
moorezilla wrote: Nice.

If you use a variable, my Rhodesian Ridgeback insists that you use "hogan" in his honor.
Done ;)

Thanks for the patch!!!  :D

All future CMSMS versions should include this.

Thanks again,

Elijah

Re: Automatically erasing search box text

Posted: Tue Feb 20, 2007 12:38 am
by moorezilla
Nice! Very Nice!

Re: Automatically erasing search box text

Posted: Fri Feb 23, 2007 10:27 pm
by fiddle
Is this only for the search module.? Can it work on pisearch, there is no such file under the pisearch module folder.  thanks

Re: Automatically erasing search box text

Posted: Fri Feb 23, 2007 11:08 pm
by Elijah Lofgren
fiddle wrote: Is this only for the search module.? Can it work on pisearch, there is no such file under the pisearch module folder.  thanks
It's even easier on Pisearch. :)
1. Go to Content -> Pisearch
2. In the Form template
Replace this line:

Code: Select all

<input type="text" value="" maxlength="50" size="15" name="pisearch" id="searching" />
with this:

Code: Select all

<input type="text" value="Search Text..." maxlength="50" size="15" name="pisearch" id="searching" onfocus="if(this.value==this.defaultValue) this.value='';" />
Hope this helps,

Elijah