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

DataObject relations support #87

Closed ghost closed 1 year ago

ghost commented 6 years ago

Hi @unclecheese, first of all thanks for your work and this helpful module. It's helping me a lot these last few weeks in my current project (running on SilverStripe 4.0.3) đź‘Ť

Actually, I noticed that apparently the feature not works with DataObject relations. For example, in this snippet of code from my project, I would hide some fields by a DropdownField value. Now, these fields are initialized by properties from another DataObject, related in a has_one with the first one. In detail:

        [...]
        private static $has_one = [
            'Sconto' => 'Sconto'
        ];
              [...]
              $fields->addFieldsToTab('Root.Coupon', array(
               [...]
                DropdownField::create('Scondo.Tipologia', 'Tipologia', array(
                    'Importo' => 'Importo',
                    'Percentuale' => 'Percentuale'
                ))->setEmptyString('Selezionare una tipologia'),
                $importo = NumericField::create('Sconto.Importo', 'Importo Sconto (€)')->setAttribute('placeholder', 'Es. 10,00'),
                $percentuale = NumericField::create('Sconto.Percentuale', 'Percentuale di Sconto (%)')->setScale(2)->setAttribute('placeholder', 'Es. 0,10'),
                [...]
            ));

            // Selective visualization
            $importo->hideUnless('Tipologia')->isEqualTo('Importo');
            $percentuale->hideUnless('Tipologia')->isEqualTo('Percentuale');
            [...]

screen shot 2018-04-10 at 12 43 19

As you can see, Importo and Percentuale are not hided. Is it my fault or the module doesn't support these type of relations?

Thanks in advance.

michalkleiner commented 1 year ago

Hello! Thank you for raising the issue and apologies it hasn't been responded to earlier.

Unfortunately, we can't provide support through the issue tracker. We recommend trying one of the Silverstripe CMS community channels such as the Forum or Slack, or asking the question on Stack Overflow. Thank you for your understanding.

Note — my tip is to use the full name including the dot, not the title of the field, or check what name is generated in the form markup in the CMS and use that. Either way, I'd still direct you Slack or the forum for such support.

If your problem persists and you think it's a bug within the Display Logic module, 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.