Automatically erasing search box text

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
moorezilla

Automatically erasing search box text

Post 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.
cyberman

Re: Automatically erasing search box text

Post by cyberman »

Like this one - will be my default for future :) ...
moorezilla

Re: Automatically erasing search box text

Post 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.
british.assassin

Re: Automatically erasing search box text

Post by british.assassin »

nice one, thanks .... i was trying to figure out how to do this myself
moorezilla

Re: Automatically erasing search box text

Post by moorezilla »

No problem, Bond. No problem.
liquid
Forum Members
Forum Members
Posts: 59
Joined: Sun Aug 07, 2005 10:20 pm

Re: Automatically erasing search box text

Post by liquid »

Wonderful, thank you!
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Automatically erasing search box text

Post by tsw »

create new feature request in forge
askme

Re: Automatically erasing search box text

Post by askme »

I am new to CMSMadeSimple..
But where is this file action.default.php is located? Which folder, subfolder of CMSmadeSimple
User avatar
webform
Power Poster
Power Poster
Posts: 505
Joined: Sat Nov 25, 2006 3:39 pm

Re: Automatically erasing search box text

Post 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;"";
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am

Re: Automatically erasing search box text

Post by Elijah Lofgren »

I think I'll try getting this into the core. :)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
moorezilla

Re: Automatically erasing search box text

Post by moorezilla »

Nice.

If you use a variable, my Rhodesian Ridgeback insists that you use "hogan" in his honor.
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am

Re: Automatically erasing search box text

Post 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
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
moorezilla

Re: Automatically erasing search box text

Post by moorezilla »

Nice! Very Nice!
fiddle

Re: Automatically erasing search box text

Post 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
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am

Re: Automatically erasing search box text

Post 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
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
Post Reply

Return to “Tips and Tricks”