Set pattern attribute depending on option
-
Hi there,
I have a plugin-option ‘numbering’, that can be set to ‘numeric’ or ‘alphanumeric’ and i like to set the value of the pattern attribute depending on the value this plugin option has been set to. Is that even possible? Here is one of my futile attempts:
public function register_metabox() { ... $mb->add_field( array( 'name' => __( 'Number', 'digipano' ), 'id' => $prefix . 'tree_number', 'type' => 'text', 'attributes' => array( 'pattern' => 'pattern_cb', ), ) ); function pattern_cb() { $settings = get_option( 'my-settings' ); $numbering = $settings['numbering']; switch ( $numbering ) { case 'numeric': return '[1-9]\d*'; case 'alphanumeric': return '[A-Z]{1}[1-9]\d*'; default: return '.*'; } } ... }
The code above is inside a class and there is a namespace, just for the case, that is important here.
Thanks in advance!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Set pattern attribute depending on option’ is closed to new replies.