default value for options other 0 can't be overridden with option with index 0

Created on 7 August 2024, 5 months ago

Problem/Motivation

if you have configured a default value for yout options (e.g. css_class plugin) and the default value is not 0, it is not possible to override the default value in an instance.

Steps to reproduce

1) configure your style_options.yml with css_class plugin and some options, set a default other than 0.

options:
  margin_top:
    plugin: css_class
    label: 'Außenabstand oben'
    multiple: false
    required: true
    options:
      - label: No margin
        class: mt-0
      - label: Small margin
        class: 'mt-2 md:mt-4 xl:mt-8'
      - label: Medium margin
        class: 'mt-4 md:mt-8 xl:mt-16'
      - label: Big margin
        class: 'mt-8 md:mt-16 xl:mt-32'
    default: 0
  margin_bottom:
    plugin: css_class
    label: 'Außenabstand unten'
    multiple: false
    required: true
    options:
      - label: No margin
        class: mb-0
      - label: Small Margin
        class: 'mb-2 md:mb-4 xl:mb-8'
      - label: Medium Margin
        class: 'mb-4 md:mb-8 xl:mb-16'
      - label: Big margin
        class: 'mb-8 md:mb-16 xl:mb-32'
    default: 2
contexts:
  paragraphs:
    _defaults:
      options:
        margin_top: true
        margin_bottom: true

2) create a content with a paragraph (the default are set like configured in your yml)
3) try to change the values -> margin_top (where the default is 0) is set with the value you configure but margin_bottom (where the default is 2) can only be overriden with index 1,2,3 and not 0 (in my case "No margin"). If i try to set thw option with index 0 the value is not saved but the default value is saved

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇦🇹Austria crmn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @crmn
  • 🇦🇹Austria crmn

    edited description

  • 🇫🇷France ccrosaz

    It is not really clear in the documentation or the example.style_options.yml, but you can use keyed option array for your values, and it solve different problems :

    • You can modify the order of the values
    • You can add and delete values
    • You can define a default value more specifically

    In your example, you can use something like:

    options:
      margin_bottom:
        plugin: css_class
        label: 'Außenabstand unten'
        multiple: false
        required: true
        options:
          nomargin:
            label: No margin
            class: mb-0
          small:
            label: Small Margin
            class: 'mb-2 md:mb-4 xl:mb-8'
          medium:
            label: Medium Margin
            class: 'mb-4 md:mb-8 xl:mb-16'
          large:
            label: Big margin
            class: 'mb-8 md:mb-16 xl:mb-32'
        default: medium
    
Production build 0.71.5 2024