-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not save empty value in option page #1509
Comments
I know this type of topic has come up in the past, regardless of it being an option or post meta keys, but I can't recall if we had reasoning behind removing the key as well as the value. I guess one question I have is why you want to keep the option key even if empty. Is there logical reason you need that? What about using the |
I don't need it. I don't do anything special for this. I just need to be able to delete a field value and that's it. This works fine for the second field. You can set the value and clear it. Because of this, it is not possible to delete the value for the first field in the interfaces at all, only to manipulate the database directly. I don't care how the data is stored, whether it's a key with an empty string, an empty array, or even deleting the field from the database. To achieve my needs, I have not come up with any other workaround than to insert another field, which will do nothing, as the very first field. $cmb = new_cmb2_box(/* ... */);
// This should be the first field to avoid issue
// https://github.com/CMB2/CMB2/issues/1509
$cmb->add_field( [
'id' => '__INTERNAL__',
'type' => 'hidden',
'sanitization_cb' => false,
'escape_cb' => false,
'default' => '1',
] );
// ... Rest field initialization |
Overall definitely sounding like a bug, from some internal discussion and what you've provided thus far. We'll need to dig in and see what's going on though, as we don't have any immediate leads. |
Describe the bug
When I create several fields on the settings page, I cannot save the state when all fields are empty.
Steps to reproduce
foo
as value in first inputExpected behavior
Both fields are empty
Actual behavior
The first field keeps the value
foo
Your Environment
CMB2 v2.10.1
php 8.1
The text was updated successfully, but these errors were encountered: