You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't set a 0 (empty) value, reverts to default #135
Whenever a user submits a value that is empty() (ie. 0, "", etc) then the field's default value is used instead.
Specifically, I'm trying to get the user to enter a number into a field. my default is 1, but 0 is a valid entry. If the user submits 0, then CMB2 sees this as an empty() value and resets it to the default (1).
Is there a way around this?
The code that seems to be affecting this is
CMB2_Field->escaped_value():
if ( false === $cb || $this->escaping_exception() ) {
// If requesting NO escaping, return meta value
return ! empty( $meta_value ) ? $meta_value : $this->args( 'default' );
}
// escaping function passed in?
$func = $func ? $func : 'esc_attr';
$meta_value = ! empty( $meta_value ) ? $meta_value : $this->args( 'default' );
There are ways around it, but I've updated the library to accept non-null values. An empty field ("") is still going to be considered null and will then trigger the default, but 0 should now work.
Activity
jtsternberg commentedon Jan 6, 2015
There are ways around it, but I've updated the library to accept non-null values. An empty field ("") is still going to be considered null and will then trigger the default, but 0 should now work.