-
Notifications
You must be signed in to change notification settings - Fork 573
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
Field value is wiped on post save if Field attributes are disabled => disabled #346
Comments
Some good thoughts here. As an alternative, you can set the |
I'm having this issue on repeatable group fields. I have a group of fields and if they choose a specific option from the select js disables other fields. The fields have default values but they get wiped out on save. I think i might have to resort to hidden fields so the value can't be changed |
readonly and disabled attributes are used for specific and varied purposes, and I'm not sure there is a good "standard" solution that should be applied here, but I am open to ideas. @modemlooper hidden fields could work, but you could also possibly remove the disabled attribute via JS when saving. That may do it. You could also use a filter like @kynetiv. Unless you guys have a specific idea as to how this be handled by default (different than it is), I think we should close this issue. |
I submitted that PR last year that covers the situation. |
If anyone is up for submitting a PR to introduce a field property |
#500 For disabling the saving of a field. Useful if you want to display the value of another field, or use a disabled/read-only field. See example in example-functions.php
I have a field with the attributes set to readonly and disabled:
I populate the field value through a separate script and just wish to display it to users without giving them the ability to update it ( readonly and disabled ).
This issue here is that because it isn't passed along in the $_POST data ( I believe because it is marked as disabled in the DOM ) the value is set to null in CMB2_Field.php on line 429:
https://github.com/WebDevStudios/CMB2/blob/master/includes/CMB2_Field.php#L429
Setting it to null is then set as the value and wipes my field's value. Instead there probably should be a check for disabled fields and not apply any update. The benefit of adding a conditional here would disallow tampering with the DOM (although there are probably other checks for that already).
As a workaround I've added a hook to the override filter here:
https://github.com/WebDevStudios/CMB2/blob/master/includes/CMB2_Field.php#L290
for my specific field_id on the filter (I may do one more generic for disabled fields in general, but right now I only have the one field):
This override filter above fixes the issue but disabled fields probably shouldn't be updated at all or require a filter like this.
The text was updated successfully, but these errors were encountered: