mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #36 from tractorcow/pulls/fix-empty-pages
BUG Fix empty pages
This commit is contained in:
commit
ab79e5cd11
@ -29,4 +29,15 @@ class UserFormsFieldList extends FieldList implements UserFormsFieldContainer {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all empty steps
|
||||
*/
|
||||
public function clearEmptySteps() {
|
||||
foreach($this as $field) {
|
||||
if($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
|
||||
$this->remove($field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ class UserForm extends Form {
|
||||
foreach ($this->controller->Fields() as $field) {
|
||||
$target = $target->processNext($field);
|
||||
}
|
||||
$fields->clearEmptySteps();
|
||||
$this->extend('updateFormFields', $fields);
|
||||
return $fields;
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ EditableFormStep:
|
||||
Title: 'Step 1'
|
||||
form5step1:
|
||||
Title: 'Step 1'
|
||||
form6step1:
|
||||
Title: 'Step 1'
|
||||
form6step2:
|
||||
Title: 'Step 2'
|
||||
form6step3:
|
||||
Title: 'Step 2'
|
||||
|
||||
EditableOption:
|
||||
option-1:
|
||||
@ -84,6 +90,12 @@ EditableTextField:
|
||||
CustomErrorMessage: Custom Error Message
|
||||
Required: true
|
||||
|
||||
field-1:
|
||||
Name: Field1
|
||||
|
||||
field-2:
|
||||
Name: Field2
|
||||
|
||||
EditableDropdown:
|
||||
basic-dropdown:
|
||||
Name: basic-dropdown
|
||||
@ -215,3 +227,7 @@ UserDefinedForm:
|
||||
Title: 'Page with filtered recipients'
|
||||
Fields: =>EditableFormStep.form5step1,=>EditableCheckboxGroupField.checkbox-group, =>EditableTextField.your-name-field, =>EditableTextField.street-field, =>EditableTextField.city-field
|
||||
EmailRecipients: =>UserDefinedForm_EmailRecipient.unfiltered-recipient-1, =>UserDefinedForm_EmailRecipient.filtered-recipient-1, =>UserDefinedForm_EmailRecipient.filtered-recipient-2
|
||||
|
||||
empty-page:
|
||||
Title: 'Page with empty step'
|
||||
Fields: =>EditableFormStep.form6step1, =>EditableTextField.field-1, =>EditableFormStep.form6step2, =>EditableTextField.field-2, =>EditableFormStep.form6step3
|
||||
|
18
tests/UserFormTest.php
Normal file
18
tests/UserFormTest.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
|
||||
class UserFormTest extends SapphireTest {
|
||||
|
||||
protected static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
|
||||
/**
|
||||
* Tests that a form will not generate empty pages
|
||||
*/
|
||||
public function testEmptyPages() {
|
||||
$page = $this->objFromFixture('UserDefinedForm', 'empty-page');
|
||||
$this->assertEquals(5, $page->Fields()->count());
|
||||
$controller = ModelAsController::controller_for($page);
|
||||
$form = new UserForm($controller);
|
||||
$this->assertEquals(2, $form->getSteps()->count());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user