statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.65k stars 500 forks source link

Clearable Select Field: Default is "Reapplied" on Update #4859

Open caseydwyer opened 2 years ago

caseydwyer commented 2 years ago

Bug description

When updating an entry with a clearable Select field, the default value is "reapplied" the next time you load the edit page via CP. So if you go in and update some other part of an Entry, you'll unintentionally/unknowingly update the Select field's value to whatever the default is.

How to reproduce

  1. Create a Collection
  2. On the Blueprint, add a Select field that's both Clearable and has a Default Value
  3. Create a new Entry for the Collection
  4. Observe the default value is entered on the Create screen
  5. Clear the default value and save the Entry
  6. Check the Entry's MD as a sanity-check (ie, to verify the Select's value is empty)
  7. Reload the Entry's edit page in CP
  8. Check the Select field; the default value has been "silently reapplied"

Logs

No response

Versions

Statamic 3.2.24 Pro
Laravel 8.73.2
PHP 7.4.3
arckinteractive/statamic-bard-font-size 1.0.0
doublethreedigital/duplicator 2.0.1
jonassiewertsen/statamic-livewire 2.7.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

arthurperton commented 2 years ago

I saw this also happens with for example a regular Text field with a default value. If you clear and save that, the default value is reapplied. I wonder if this is the intended behaviour for fields with a default value?

caseydwyer commented 2 years ago

I saw this also happens with for example a regular Text field with a default value. If you clear and save that, the default value is reapplied. I wonder if this is the intended behaviour for fields with a default value?

Good find; sounds like field type doesn't really matter here.

It definitely makes sense when initially creating an entry...but the "reapplication" of the default—when editing an existing record—feels like a bug to me.