getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.58k stars 1.41k forks source link

[Bug] Empty Form Field Toggle State Defaults to On When Blueprint is Imported #3507

Open memtech3 opened 2 years ago

memtech3 commented 2 years ago

Issue

Empty page form fields marked toggleable: true are defaulting to enabled in admin. When the icon partial was tested on its own as a module empty fields defaulted to disabled. I have posted the relevant blueprints below.

All related code

The entire Grav installation used can be found at: https://github.com/memtech3/Duck-Picnic-Development-Environment The theme code used can be found at: https://github.com/memtech3/duck-picnic on the icon-partial branch

Blueprints with import:

modular/statpanels.yaml

title: Stat Panels
'@extends': default

form:
  fields:
    tabs:
      fields:
        statpanels:
          type: tab
          title: Stat Panels
          fields:
            header.statpanels:
              name: statpanels
              type: list
              label: Stat Panels
              fields:
                .icon:
                  type: section
                  title:
                  import@:
                    type: partials/icon
                .header:
                  type: text
                  label: Statistic
                .text:
                  type: editor
                  label: Text

partials/icon.yaml

form:
  fields:
    .icon:
      type: iconpicker
      label: Icon
      toggleable: true
    .color:
      type: colorpicker
      label: Icon Color
      toggleable: true
    .image:
      type: mediapicker
      folder: 'user/pages/images'
      label: Select an image to use as an icon
      preview_images: true
      toggleable: true
    .imageurl:
      type: text
      label: Input a url to use as an icon
      toggleable: true
    .header:
      type: text
      label: Header
      toggleable: true
    .link:
      type: text
      label: Link
      toggleable: true

Blueprints for module without import:

modular/icon.yaml

title: Icon
'@extends': default

form:
  fields:
    tabs:
      fields:
        header.icon:
          type: tab
          title: Icon
          fields:
            .icon:
              type: iconpicker
              label: Icon
              toggleable: true
            .color:
              type: colorpicker
              label: Icon Color
              toggleable: true
            .image:
              type: mediapicker
              folder: 'user/pages/images'
              label: Select an image to use as an icon
              preview_images: true
              toggleable: true
            .imageurl:
              type: text
              label: Input a url to use as an icon
              toggleable: true
            .header:
              type: text
              label: Header
              toggleable: true
            .link:
              type: text
              label: Link
              toggleable: true
m-schmale commented 2 years ago

Maybe a similar issue: https://github.com/getgrav/grav-plugin-admin/issues/2217 I think I've fixed it for me.

memtech3 commented 2 years ago

I tried adding your code between line 72 and 73 but that doesn't seem to change the behavior even after I remove the keys and values saved as null from the page frontmatter.

{% if default_layout != 'key' %}
{% set originalValue = child_value %}
{% endif %}
m-schmale commented 2 years ago

@memtech3 I've created a modular/statpanels.yaml and a partials/icon.yaml with your content, but I cannot reproduce your issue. I did not changed anything in the code (Grav v1.7.25). The fields are still disabled even after I've saved the form.

image

This is what the frontmatter looks like:

title: Test
body_classes: modular
statpanels:
    -
        header: null
        text: null
memtech3 commented 2 years ago

I just downloaded the latest version of grav+admin (1.7.26.1, 1.10.26.1), installed my theme in it, and I am still having the issue. Can you try installing my theme? The relevant code is on the main branch https://github.com/memtech3/duck-picnic. The module is called statpanels.

Some other info: I am running php -S localhost:8000 system/router.php on Ubuntu 21.10 with PHP 8 and the PHP 8 versions of all the required PHP extensions maybe this is a php 8 issue? maybe there are issues with the PHP 8 versions of the extensions?

memtech3 commented 2 years ago

I just noticed that the imageurl field toggle does not automatically toggle on like the rest of the fields image

spamhater-grav commented 2 years ago

Ok I am hoping that I am understanding the problem and what you are trying to return but I ended up with a few little tweaks

statpanels.yaml

title: Stat Panels
'@extends': default

form:
  fields:
    tabs:
      fields:
        statpanels:
          type: tab
          title: Stat Panels
          fields:
            header.statpanels_section:
              type: section
              title: Page Headings
              underline: true
            header.statpanels:
              type: list
              collapsed: true
              import@:
                type: partials/icon

icons.yaml

form:
  fields:
    .icon:
      type: iconpicker
      label: Icon
      toggleable: true
    .color:
      type: colorpicker
      label: Icon Color
      toggleable: true
    .image:
      type: mediapicker
      folder: 'user/pages/images'
      label: Select an image to use as an icon
      preview_images: true
      toggleable: true
    .imageurl:
      type: text
      label: Input a url to use as an icon
      toggleable: true
    .header:
      type: text
      label: Header
      toggleable: true
    .smalltext:
      type: text
      label: Small Text
      toggleable: true
    .link:
      type: text
      label: Link
      toggleable: true

which returned the data to statpanels.md


---
title: statpanels
body_classes: modular
statpanels:
    -
        icon: 'fa fa-file-o'
        color: '#992828'
        header: Testing
        smalltext: Small
    -
        icon: 'fa fa-arrow-circle-o-down'
        color: '#593e3e'
        header: 2nd
---

Is this your required result ?