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

Setup step missing? #28

Closed mattkibbler closed 9 years ago

mattkibbler commented 10 years ago

The DisplayLogic method that sets up the Requirements and returns the script for the logic criteria doesn't appear to be called anywhere when I'm using this simple implementation:

$field->displayIf("OtherField")->isChecked();

Am I missing something here?

unclecheese commented 10 years ago

That should work. The most common issue I see with this module is that you have to run ?flush from within the admin, not just from the frontend, to get all the new requisite form field templates loaded.

On 6/08/2014, at 8:54, mattkibbler notifications@github.com wrote:

The DisplayLogic method that sets up the Requirements and returns the script for the logic criteria doesn't appear to be called anywhere when I'm using this simple implementation:

$field->displayIf("OtherField")->isChecked(); Am I missing something here?

— Reply to this email directly or view it on GitHub.

mattkibbler commented 10 years ago

Thanks for the quick response.

Yep, I tried that and have done it again to be sure.

Here is my exact example:

$fields->addFieldsToTab("Root.Settings", array(
    UploadField::create("BrandImage"),
    ColorField::create("BrandColour"),
    ColorField::create("TextColour"),
    TextField::create("FacebookAccessToken"),
    $useExposeField = CheckboxField::create("UseExpose"),
    $exposeSpeedField = NumericField::create("ExposeSpeed"),
    $exposeLengthField = NumericField::create("ExposeLength"),
    $exposeTimeoutField = NumericField::create("ExposeTimeout"),
    $displayTimeField = NumericField::create("DisplayTime")
));

$exposeSpeedField->displayIf("UseExpose")->isChecked();

And this is the form field that I am getting:

<div id="ExposeSpeed" class="field numeric text display-logic display-logic-hidden display-logic-display">
    <label class="left" for="Form_EditForm_ExposeSpeed">Expose Speed</label>
    <div class="middleColumn">
        <input type="text" name="ExposeSpeed" value="0" class="numeric text display-logic display-logic-hidden display-logic-display" id="Form_EditForm_ExposeSpeed">
    </div>  
</div>

I don't get any of the requirements, CSS or JS, output on the page.

I can actually force the requirements to appear by calling this manually:

$exposeSpeedField->DisplayLogic();

... but of course I don't get the JS for the conditional field anywhere.

unclecheese commented 10 years ago

Thanks for the code. I'll run a test.

On 6/08/2014, at 9:17, mattkibbler notifications@github.com wrote:

Thanks for the quick response.

Yep, I tried that and have done it again to be sure.

Here is my exact example:

$fields->addFieldsToTab("Root.Settings", array( UploadField::create("BrandImage"), ColorField::create("BrandColour"), ColorField::create("TextColour"), TextField::create("FacebookAccessToken"), $useExposeField = CheckboxField::create("UseExpose"), $exposeSpeedField = NumericField::create("ExposeSpeed"), $exposeLengthField = NumericField::create("ExposeLength"), $exposeTimeoutField = NumericField::create("ExposeTimeout"), $displayTimeField = NumericField::create("DisplayTime") ));

$exposeSpeedField->displayIf("UseExpose")->isChecked(); And this is the form field that I am getting:

I don't get any of the requirements, CSS or JS, output on the page.

I can actually force the requirements to appear by calling this manually:

$exposeSpeedField->DisplayLogic(); ... but of course I don't get the JS for the conditional field anywhere.

— Reply to this email directly or view it on GitHub.

unclecheese commented 10 years ago

Sorry for the delay. I was able to run a test using your code and it works as expected. Are you still having issues? If so, maybe provide more context, like say, the whole class?

mspacemedia commented 10 years ago

Hi, hijacking but I get the same missing requirements using the latest release 1.0.5 and SS3.1.6 - no css, js or entwine is injected into HTML - fields all get the correct 'display-logic' classes though. Have flushed and flushed and flushed frontend and admin.

unclecheese commented 9 years ago

@mspacemedia Try making a subtle change to one of the form field templates that comes with display_logic, and see if that renders. It should be using the templates that come with the module, not the core. If it's using core templates, you won't get any script.

The classes are injected via the controller, so that's expected either way.