unclecheese / silverstripe-display-logic

The Display Logic module allows you to add conditions for displaying or hiding certain form fields based on client-side behavior.
BSD 3-Clause "New" or "Revised" License
74 stars 71 forks source link

(minor) Compatibility Issue with Elemental #104

Closed thezenmonkey closed 1 year ago

thezenmonkey commented 5 years ago

Can't use ShowTitle checkbox field on BaseElement as a trigger. Likely because it's part of TextCheckboxGroupField instead of a regular CheckboxField. It's minor, but since Elemental is pretty core to SS moving forward it would be useful if we could use that field as a trigger.

social-butterfly commented 5 years ago

Did you get it working in Elemental otherwise? I'm having issues with SS4.3 and Elemental. I get an error

Fatal Error (E_USER_ERROR): SilverStripe\Forms{closure}() I noticed that a field called 'VideoType' appears twice {"code":256,"message":"SilverStripe\Forms\{closure}()... 'VideoType' appears twice","file":"X:\project\vendor\silverstripe\framework\src\Forms\FieldList.php","line":175,"trace":[ ...

However, I only have the VideoType field once in my Elemental Block (custom block). Code:

<?php
    use DNADesign\Elemental\Models\BaseElement;
    use UncleCheese\DisplayLogic\Forms\Wrapper;
    use SilverStripe\Forms\OptionsetField;

    class CustomMediaElement extends BaseElement
    {
        ...Model definitions etc...

        public function getCMSFields() {
            $fields = parent::getCMSFields();

            $fields->addFieldToTab(
                'Root.Main',
                $mediatype = new OptionsetField(
                    'MediaType',
                    'Media Type'
                )
            );
            $mediatype->setSource(array(
                'I' => 'Image',
                'V' => 'Video',
                'A' => 'Audio'
            ));
            $mediatype->setEmptyString('');

            $fields->addFieldToTab(
                'Root.Main',
                Wrapper::create(
                    OptionsetField::create(
                        'VideoType',
                        'Video Type',
                        array(
                            'Y' => 'YouTube',
                            'V' => 'Vimeo'
                        )
                    )
                )->displayIf('MediaType')->isEqualTo('V')->end()
            );

            return $fields;
        }

        public function getType() {
            return 'Custom Media';
        }
    }
ishannz commented 5 years ago

Im having the same issue when I am using the Wrapper inside Elemental.

ishannz commented 5 years ago

you can use replaceField instead of creating new, $fields->replaceField('VideoType', Wrapper::create( OptionsetField::create( 'VideoType', 'Video Type', array( 'Y' => 'YouTube', 'V' => 'Vimeo' ) ) ) )

Did you get it working in Elemental otherwise? I'm having issues with SS4.3 and Elemental. I get an error

Fatal Error (E_USER_ERROR): SilverStripe\Forms{closure}() I noticed that a field called 'VideoType' appears twice {"code":256,"message":"SilverStripe\Forms{closure}()... 'VideoType' appears twice","file":"X:\project\vendor\silverstripe\framework\src\Forms\FieldList.php","line":175,"trace":[ ...

However, I only have the VideoType field once in my Elemental Block (custom block). Code:

<?php
  use DNADesign\Elemental\Models\BaseElement;
  use UncleCheese\DisplayLogic\Forms\Wrapper;
  use SilverStripe\Forms\OptionsetField;

  class CustomMediaElement extends BaseElement
  {
      ...Model definitions etc...

      public function getCMSFields() {
          $fields = parent::getCMSFields();

          $fields->addFieldToTab(
              'Root.Main',
              $mediatype = new OptionsetField(
                  'MediaType',
                  'Media Type'
              )
          );
          $mediatype->setSource(array(
              'I' => 'Image',
              'V' => 'Video',
              'A' => 'Audio'
          ));
          $mediatype->setEmptyString('');

          $fields->addFieldToTab(
              'Root.Main',
              Wrapper::create(
                  OptionsetField::create(
                      'VideoType',
                      'Video Type',
                      array(
                          'Y' => 'YouTube',
                          'V' => 'Vimeo'
                      )
                  )
              )->displayIf('MediaType')->isEqualTo('V')->end()
          );

          return $fields;
      }

      public function getType() {
          return 'Custom Media';
      }
  }
michalkleiner commented 1 year ago

I believe the display logic mechanism would work if the correct field name was used. If that was not possible, it would still be an issue worth raising at the Elemental module.

Closing this issue since it's outdated and we're now on Silverstripe CMS 4.12.0 and Display Logic 2.0.5.

If the problem with the Display Logic module persists, feel free to open a new bug report and provide replication steps and information on what version of Silverstripe CMS and the module you're using.

ScottPenhall98 commented 1 year ago

Another solution I found was using inline editable on your Element Model private static $inline_editable = false;