carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

[File Field] In complex field, the value is still saved despite conditional logic

Open vladolaru opened this issue 3 years ago • 0 comments

Version

  • Carbon Fields: 3.3.2
  • WordPress: 5.7.1
  • PHP: 7.4

I am in a post meta situation. I have a file field inside a complex field (it may happen with just a plain file field also) and that complex field is used conditionally.

Expected Behavior

When the parent complex field is not used, the file field value should not be saved in the DB.

Actual Behavior

On post save, the file field value as part of the complex field gets saved in the DB, despite the fact that other fields part of the complex field do not.

The problem

The problem emerges from the fact that the file field holds its value in a hidden, read-only input. When the conditional logic runs, if a certain field is disabled then its inputs get the disabled HTML attribute so they are not submitted on POST or GET.

The trouble is that the disable logic excludes inputs that are hidden: https://github.com/htmlburger/carbon-fields/blob/development/packages/core/components/disabled/index.js#L78

The solution

I am not exactly sure, but I believe that hidden inputs should not be excluded when conditional logic is used.

vladolaru avatar May 12 '21 08:05 vladolaru