Support Forum
Support › General › Suggestion for fields — Automatically adding a TITLE ATRIBUTE based on MB IDResolved
Hello guys!
I have a suggestion for future MetaBox versions — is it possible to add a TITLE attribute automatically based on the ID of a metabox field? It is super useful when you are developing interfaces based on metaboxes.
You just move the cursor on top of it and the browser tooltip refreshes your memory with a instantaneous info!
Otherwise you need to check the source code or use other cluttering tools for a so simple process.
When editing in admin metaboxes fields are generated this way:
<input size="30" type="text" id="famicom" class="rwmb-text" name="famicom" />
My suggestion:
<input size="30" type="text" id="famicom" class="rwmb-text" name="famicom" title="famicom" />
Where the "title" attribute is equal as the field ID. And of course, to apply not only on INPUT:text, but also in all kind of fields generated by MB plugin!
What do you think?
Thank you so much for this wonderful suite of MAGIC!
Love metaBox!
G.
Well,
I just accomplished a satisfactory result injecting some custom jQuery on WordPress admin. Using the code below I can force the most common fields to have a TITLE attribute based on their IDs:
jQuery('input, textarea, select, .wp-color-picker').each(function(){
jQuery(this).attr('title', jQuery(this).attr('id'));
});
jQuery('.rwmb-switch').each(function(){
jQuery(this).next().attr('title', jQuery(this).attr('id'));
});
jQuery('label').each(function(){
jQuery(this).attr('title', jQuery(this).attr('for'));
});
Hope to be useful to someone!
G.
Hi Giovani,
Thanks for your idea.
WordPress requires the meta box's title when registering, we've also noted this case on the documentation when creating the meta box:
id
Meta box ID, must be unique. Optional. If it’s absent, it will be generated from title
using sanitize_title
function.
title
Meta box title. Required.
https://docs.metabox.io/creating-meta-boxes/#meta-box-settings
title
is required and id
is optional, it will be generated from title
.
Hello, Long.
Yes yes, I understand perfectly, but I was talking about the attribute title IN A FIELD itself, not the general title of a array of fields — the whole metabox thing.
My suggestion:
<img id="my-id" src="xxx" alt="abc" TITLE="my-id" />
<input type="text" id="my-id2" size="30" TITLE="my-id2" />
<select id="my-id3" name="pick-a-boo" title="my-id3"> ... </select>
What we have today:
<img id="my-id" src="xxx" alt="abc" />
<input type="text" id="my-id2" size="30" />
<select id="my-id3" name="pick-a-boo"> ... </select>
It could be added on the metabox root code, however I can'r mess up the core code there, because it will me lost upon updating:
if ( class_exists( 'RWMB_Field' ) ) {
class RWMB_Phone_Field extends RWMB_Field {
public static function html( $meta, $field ) {
return sprintf(
'<input type="tel" name="%s" id="%s" value="%s" title="%s">',
$field['field_name'],
$field['id'],
$meta,
$field['id'] // <------- THIS
);
}
}
}
Well, just and idea. I found a workaround using jQuery, but it would be great to have this implemented, at least on INPUT, SELECT, TEXTAREA.
Thank you!
This:
And this:
=)
Hi,
Thanks for your effort.
The attribute title for each field helps users to show the short description when hovering the element. We also have the extension Meta Box Tooltip to show the description as well.
But I will discuss with the developer team to take a look at this case and support in the future update if needed.
Oh!
Metabox TOOLTIP. I was completely unaware of this extension. Thanks for the suggestion. Really nice indeed!
Best regards,
G.