I’d check the “attributes” section of https://github.com/WebDevStudios/CMB2/wiki/Field-Types#common-field-parameters. It outlines how to pass some extra attributes for each field including required="required"
Absolutely appreciated that. Must have missed it when I was looking 😀
Can you please make that this attribute add one asterisk in different color after label ?
Name (*).
Means a lot for Users before they hit Save/Update button.
Stagger Lee, not sure we have anything like that built in, but we do have callbacks available.
I have tinkered and tested with this one and it should do nicely enough
Add this to your add_field list of parameters:
'label_cb' => 'sl_asterisk_for_required_label'
and then add this to your file so that it’s available when the metaboxes are run:
function sl_asterisk_for_required_label( $args = array(), $field = '' ) {
$label = '<label for="' . $args['id'] . '">';
$label .= $args['name'];
if ( !empty( $args['attributes']['required'] ) && 'required' == $args['attributes']['required'] ) {
$label .= ' <span style="color:red">*</span>';
}
$label .= '</label>';
return $label;
}
Should get used any time you pass in the label_cb
param first mentioned.
Thank you. Works very nice.
Making entries in my private snippets searchable database. No way I would remember tomorrow all this. Dont know what I had for dinner yesterday.