Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with multiple forms on one page #115

Open
kinglozzer opened this issue Jun 15, 2020 · 2 comments
Open

Issue with multiple forms on one page #115

kinglozzer opened this issue Jun 15, 2020 · 2 comments

Comments

@kinglozzer
Copy link

If two (or more) forms rendered on one page have a field with the same name, display-logic criteria is added to both - even if one doesn’t have any logic applied.

// Form A
$fields = FieldList::create(
    $text = TextField::create('Title', 'Title')
);
$text->displayIf('Title')->isEqualTo('Bar')

// Form B
$fields = FieldList::create(
   TextField::create('Title', 'Some unrelated title')
);

The title fields for both forms will get data-display-logic-eval etc added. This is because extensions in SilverStripe are singletons by default, so the $this->displayLogicCriteria array will be stored for all forms:

$id = $this->owner->getName();
return isset($this->displayLogicCriteria[$id]) ? $this->displayLogicCriteria[$id] : null;

Fix is to add the following YAML config:

SilverStripe\Core\Injector\Injector:
  UncleCheese\DisplayLogic\Extensions\DisplayLogic:
    type: 'prototype'
@michalkleiner
Copy link
Collaborator

Would this mostly happen with front-end forms? How would you get a field with the same name in two forms on one page in the CMS?

@kinglozzer
Copy link
Author

Yep this was referring to front-end forms, I haven’t tested recently though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants