TypeRocket / core

TypeRocket core source files where all the magic lives.
https://typerocket.com
36 stars 21 forks source link

checkbox->setDefault bug #47

Closed zackphilipps closed 5 years ago

zackphilipps commented 5 years ago

Hey @kevindees,

Curious about your thoughts on this. https://github.com/TypeRocket/core/blob/master/src/Elements/Fields/Checkbox.php#L34

Because unchecking the box and clicking "save" removes the row from the DB entirely, if you've setDefault( true ), the checkbox will be checked again. D:

kevindees commented 5 years ago

@zackphilipps

The saving of metadata should not be removing it because the value is set to 0 and not an empty string. Might be a condition that should be set on saving to fix the bug.

$value !== 0 && $value !== '0'

zackphilipps commented 5 years ago

Actually.... Unchecking doesn't appear to do anything. The value is still saved in the DB as 1.

kevindees commented 5 years ago

@zackphilipps

Interesting bug. Can you send your code with context? Will help me create a patch for this.

kevindees commented 5 years ago

@zackphilipps

If you had the field as a text or select box before sometimes you need to clear out the old data because the new field type does know what to do with the old data.

zackphilipps commented 5 years ago

@zackphilipps Disregard. Sorry. In this particular project I had commented out something important. Oops!