9
Jul
One of the most useful thing on forms is an “autoselect” function. How is this work? Let’s assume that you have a standard search box:

When textbox is focused you can do three things:
- Do nothing. Let the user to delete all text. Not good for lazy people, right?
- Autoclear box. But if user want only to change a letter (typo) or add another word, then he should re-type all things. Not good for usability.
- Autoselect box content. Is just like the user double clicks on the text. How can you do this? Read further to see
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| var initValue;
$(document).ready(function(){
$(':text').each(function(){
$(this).focus(function(){
initValue = $(this).attr('value');
$(this).select();
});
$(this).blur(function(){
if($(this).val() == ''){
$(this).val(initValue);
}
});
});
}); |
What is the best thing with this? Well… If an user just leave the text box blank, that form is auto filled with previous value.
Pretty nice, huh? Well… I think is pretty useful too
30
Jun
Today i spent some time trying to figure how to get existing (and also used) tags from wordpress and using in admin panel as a combo box, for my brand new theme Wordnewz.
The return of get_tags() function was some kind of array but, because of my skills (not) in PHP i spend WAY too much time to go figure what to do. The initial result of get_tags() function is:
Array
(
[0] => stdClass Object
(
[term_id] => 28
[name] => Featured
[slug] => featured
[term_group] => 0
[term_taxonomy_id] => 29
[taxonomy] => post_tag
[description] =>
[parent] => 0
[count] => 6
)
)
And i only needed [name] and [slug]. Ofcourse, like a smart guy that i am, i pointed my browser on wordpress codex where i found… NOTHING. Nothing about this function… Great. Let’s try various stuff and google it for any ideas. And i found a PHP function get_object_vars for easy conversion. After this, all was GREAT. I use it like this:
1
2
3
4
5
| $allTags = get_tags();
foreach($allTags as $thisTags) {
$thisTag = get_object_vars($thisTags);
echo '<option value="'.$thisTag['slug'].'">'.$thisTag['name'].'</option>\n';
} |
And it WORKS like a charm. I posted this thing because i didn’t found too much references for stdClass Object or get_tags() Wordpress function.