2017 © Pedro Peláez
 

silverstripe-vendormodule display-logic

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

image

silverstripe/display-logic

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  • Monday, February 26, 2018
  • by unclecheese
  • Repository
  • 21 Watchers
  • 65 Stars
  • 19,573 Installations
  • PHP
  • 13 Dependents
  • 0 Suggesters
  • 52 Forks
  • 27 Open issues
  • 29 Versions
  • 8 % Grown

The README.md

Display Logic Module for SilverStripe 4

Description

The Display Logic module allows you to add conditions for displaying or hiding certain form fields based on client-side behavior., (*1)

Example usage

<?php
$products->displayIf("HasProducts")->isChecked();

$sizes->hideUnless("ProductType")->isEqualTo("t-shirt")
      ->andIf("Price")->isGreaterThan(10);

$payment->hideIf("Price")->isEqualTo(0);

$shipping->displayIf("ProductType")->isEqualTo("furniture")
           ->andIf()
              ->group()
                ->orIf("RushShipping")->isChecked()
                ->orIf("ShippingAddress")->isNotEmpty()
              ->end();

Available comparison functions

- isEqualTo
- isNotEqualTo
- isGreaterThan
- isLessThan
- contains
- startsWith
- endsWith
- isEmpty
- isNotEmpty
- isBetween
- isChecked
- isNotChecked()
- hasCheckedOption
- hasCheckedAtLeast
- hasCheckedLessThan

Available display conditions

- displayIf()
- displayUnless()
- hideIf()
- hideUnless()

Kitchen sink example

<?php
  public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldsToTab("Root.Test", array(
            TextField::create("Name","Name of event"),
            TextField::create("VenueSize","Size of venue"),
            $refreshments = CheckboxField::create("Refreshments","This is a large venue. Are there refreshments?"),                         
            $vendors = CheckboxSetField::create("Vendors","Vendors", Member::get()->map()),             
            $tent = TextField::create("TentSize","You're going to need a tent. What size is it?"),

            OptionSetField::create("LinkType", "", array('internal' => 'Link to an internal page', 'external' => 'Link to an external page')),
            $internal = DropdownField::create("InternalLinkID", "Choose a page", SiteTree::get()->map()->toArray())->setEmptyString("-- choose --"),
            $external = TextField::create("ExternalLink", "Link to external page"),
            $label = TextField::create("LinkLabel", "Label for link"),

            $useEmbed = CheckboxField::create("UseEmbedCode","I have embed code"),
            $embed = TextareaField::create("EmbedCode","Enter the embed code.")

        ));                     

        $refreshments->displayIf("VenueSize")->isGreaterThan(100);
        $vendors->displayIf("Refreshments")->isChecked();
        $tent->displayIf("Vendors")->hasCheckedAtLeast(3);


        $internal->displayIf("LinkType")->isEqualTo("internal");                
        $external->displayIf("LinkType")->isEqualTo("external");
        $label->displayIf("LinkType")->isEqualTo("internal")->orIf("LinkType")->isEqualTo("external");

        $useEmbed->displayIf("LinkType")->isEqualTo("external");
        $embed->displayIf("UseEmbedCode")->isChecked()
                    ->orIf()
                        ->group()
                            ->orIf("ExternalLink")->contains("youtube.com")
                            ->orIf("ExternalLink")->contains("vimeo.com")
                        ->end();


        return $fields;
    }

Kitchen sink example, with chaining

<?php

use UncleCheese\DisplayLogic\Forms\Wrapper;
//...
  public function getCMSFields() {
        $f = parent::getCMSFields();
        $f->addFieldsToTab("Root.Test", array(
            TextField::create("Name","Name of event"),
            TextField::create("VenueSize","Size of venue"),
            CheckboxField::create("Refreshments","This is a large venue. Are there refreshments?")
                ->displayIf("VenueSize")->isGreaterThan(100)->end(),
            CheckboxSetField::create("Vendors","Vendors", Member::get()->map())
                ->displayIf("Refreshments")->isChecked()->end(),
            TextField::create("TentSize","You're going to need a tent. What size is it?")
                ->displayIf("Vendors")->hasCheckedAtLeast(3)->end(),
            CheckboxField::create('HasUpload', 'Has an upload'),

            Wrapper::create(
                UploadField::create('FileUpload', 'Upload a file'),
                LiteralField::create('test', '<strong>Keep the file small!</strong>')
            )->displayIf('HasUpload')->isChecked()->end(),

            OptionSetField::create("LinkType", "", array('internal' => 'Link to an internal page', 'external' => 'Link to an external page')),
            DropdownField::create("InternalLinkID", "Choose a page", SiteTree::get()->map()->toArray())->setEmptyString("-- choose --")
                ->displayIf("LinkType")->isEqualTo("internal")
                ->end(),
            TextField::create("ExternalLink", "Link to external page")
                ->displayIf("LinkType")->isEqualTo("external")
                ->end(),
            Wrapper::create(
                ReadonlyField::create('URL','Base URL','http://example.com')
            )->displayIf('LinkType')->isEqualTo('internal')->end(),
            TextField::create("LinkLabel", "Label for link")
                ->displayIf("LinkType")->isChecked()->end(),
            CheckboxField::create("UseEmbedCode","I have embed code")
                ->displayIf("LinkType")->isEqualTo("external")              
                ->end(),
            TextareaField::create("EmbedCode","Enter the embed code.")
                ->displayIf("UseEmbedCode")->isChecked()
                    ->orIf()
                        ->group()
                            ->orIf("ExternalLink")->contains("youtube.com")
                            ->orIf("ExternalLink")->contains("vimeo.com")
                        ->end()
        ));                     

        return $f;
    }

Dealing with non-standard form fields

Sometimes you will want to wrap display logic around a form field that does not use the standard FormField template, such as GridField or LiteralField. For these cases, you can wrap the form field in UncleCheese\DisplayLogic\Forms\Wrapper., (*2)

$fields->addFieldToTab("Root.Main", Wrapper::create(
        LiteralField::create("foo","<h2>Hello</h2>")
    )
    ->displayIf("Title")->isEmpty()->end()
);

What's the difference between displayIf() and hideUnless()?

Not much. hideUnless() will take a CSS class that hides it by default before the script loads, to eliminate any flash of form fields before the script has loaded. In general, use displayIf() when the common case is for the field to be hidden, and hideUnless() when the common case is for the field to be shown. The same logic applies to hideIf() and displayUnless()., (*3)

The Versions

26/02 2018

dev-master

9999999-dev

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cms silverstripe forms logic display

26/02 2018

2.0.1

2.0.1.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cms silverstripe forms logic display

19/02 2018

2.0.0

2.0.0.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cms silverstripe forms logic display

06/01 2017

1.5.0

1.5.0.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

01/12 2016

1.4.3

1.4.3.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

28/09 2016

1.4.2

1.4.2.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

15/08 2016

1.4.1

1.4.1.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

22/07 2016

1.4.0

1.4.0.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

21/06 2016

1.3.3

1.3.3.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

04/06 2016

1.2.4

1.2.4.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

17/05 2016

1.2.3

1.2.3.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

14/12 2015

1.3.2

1.3.2.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

30/10 2015

1.3.1

1.3.1.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

30/10 2015

1.2.x-dev

1.2.9999999.9999999-dev

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

30/10 2015

1.2.2

1.2.2.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

30/10 2015

1.3.0

1.3.0.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

30/01 2015

1.2.1

1.2.1.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

19/01 2015

1.2.0

1.2.0.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

19/01 2015

dev-feature/remove-custom-templates

dev-feature/remove-custom-templates

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

23/12 2014

1.1.0

1.1.0.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

08/12 2014

1.0.8

1.0.8.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

25/11 2014

1.0.7

1.0.7.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

21/11 2014

1.0.6

1.0.6.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

08/10 2014

1.0.5

1.0.5.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

02/07 2014

1.0.4

1.0.4.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

23/06 2014

1.0.3

1.0.3.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

06/05 2014

1.0.2

1.0.2.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

26/03 2014

1.0.1

1.0.1.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display

28/02 2014

1.0

1.0.0.0

Allows assignment of conditions for display and hide of specific form fields based on client side behavior.

  Sources   Download

BSD-3-Clause

The Requires

 

cms silverstripe forms logic display