statamic / cms

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

Default values in navigation blueprints don't save #9423

Open robdekort opened 9 months ago

robdekort commented 9 months ago

Bug description

When you edit your navigation blueprint and set default values for certain fields, they don't save. So this example:

Screenshot 2024-01-31 at 09 53 16

Will save like this:

  -
    id: ab914f41-c4d2-4ecc-9f76-5a324347a6a1
    title: Hey

It should be:

  -
    id: ab914f41-c4d2-4ecc-9f76-5a324347a6a1
    title: Hey
    data:
      select: jack
      down_under: yeah_nah
      addon_devs: sleight
      toggle: true

There might be more fields (or simply all) where this happens with, but these are the one I've noticed this behaviour for over time. This behaviour is unwanted when you expect data to be there. A workaround is not to set a default and make the field required.

How to reproduce

Thy this navigation blueprint and add an entry and save it (without touching the fields):

tabs:
  main:
    display: Main
    sections:
      -
        display: General
        fields:
          -
            handle: select
            field:
              options:
                jack: Jack
                jason: Jason
                jesse: Jesse
                joshua: Joshua
                duncan: Duncan
              taggable: false
              push_tags: false
              multiple: false
              clearable: false
              searchable: true
              cast_booleans: false
              default: jack
              type: select
              display: Select
              listable: hidden
              instructions_position: above
              visibility: visible
              replicator_preview: true
              hide_display: false
          -
            handle: down_under
            field:
              options:
                yeah_nah: 'Yeah nah'
                nah_yeah: 'Nah yeah'
              default: yeah_nah
              type: button_group
              display: 'Down under'
              listable: hidden
              instructions_position: above
              visibility: visible
              replicator_preview: true
              hide_display: false
          -
            handle: addon_devs
            field:
              options:
                sleight: Sleight
                mitchell: Mitchell
              inline: false
              cast_booleans: false
              default: sleight
              type: radio
              display: 'Addon devs'
              listable: hidden
              instructions_position: above
              visibility: visible
              replicator_preview: true
              hide_display: false
          -
            handle: toggle
            field:
              inline_label: 'Save me!'
              default: true
              type: toggle
              display: Toggle
              listable: hidden
              instructions_position: above
              visibility: visible
              replicator_preview: true
              hide_display: false

Logs

No response

Environment

Application Name: Statamic Peak Development
Laravel Version: 10.42.0
PHP Version: 8.3.0
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
URL: statamic-peak.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 4
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.46.0 PRO

Statamic Addons
studio1902/statamic-peak-browser-appearance: 3.3.4
studio1902/statamic-peak-commands: 5.0.0
studio1902/statamic-peak-seo: 8.0.0
studio1902/statamic-peak-tools: 4.4.0

Installation

Starter Kit using via CLI

Antlers Parser

None

Additional details

No response

duncanmcclean commented 5 months ago

The fact the default values aren't being saved to the YAML file here won't be such a big deal in Statamic 5 since they'll automatically pull through in templates (or anywhere else augmentation happens) if no value is set. See #9010.

jasonvarga commented 5 months ago

True but it's still weird that they don't get saved. They should.

JonKaric commented 1 week ago

@duncanmcclean

The fact the default values aren't being saved to the YAML file here won't be such a big deal in Statamic 5 since they'll automatically pull through in templates (or anywhere else augmentation happens) if no value is set. See #9010.

This no longer seems to be the case anymore :( I think the values getting saved would help with debugging aswell as (maybe?) solve this error entirely?

Blueprint:

tabs:
  main:
    display: Main
    sections:
      -
        fields:
          -
            handle: type
            field:
              options:
                -
                  key: column
                  value: Column
                -
                  key: link
                  value: Link
              type: select
              display: Type
              localizable: false
              default: link
{{ nav:main_navigation }}
    {{ title }}    
    {{ type }}

    {{ children }}
        {{ title }}
        {{ type }}
    {{ /children }}
{{ /nav:main_navigation }}
tree:
  -
    id: 26cf267f-b796-45ff-b9d7-9ba55284f6a6
    title: 'Test 1'
    data:
      type: column
    children:
      -
        id: c4402515-2117-446d-8cb4-01bfe5b491e7
        title: Test 2

Result:

Test 1 column 
Test 2 column