mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #754 from creative-commoners/pulls/5.0/allow-empty-field-titles
FIX Allow editable form fields to have nullable titles rather than fallback to Name
This commit is contained in:
commit
0a9f3f4365
@ -44,7 +44,7 @@ class EditableCheckbox extends EditableFormField
|
||||
|
||||
public function getFormField()
|
||||
{
|
||||
$field = CheckboxField::create($this->Name, $this->Title, $this->CheckedDefault)
|
||||
$field = CheckboxField::create($this->Name, $this->Title ?: false, $this->CheckedDefault)
|
||||
->setFieldHolderTemplate(__CLASS__ . '_holder')
|
||||
->setTemplate(__CLASS__);
|
||||
|
||||
|
@ -25,7 +25,7 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField
|
||||
|
||||
public function getFormField()
|
||||
{
|
||||
$field = UserFormsCheckboxSetField::create($this->Name, $this->Title, $this->getOptionsMap())
|
||||
$field = UserFormsCheckboxSetField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
|
||||
->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder')
|
||||
->setTemplate(UserFormsCheckboxSetField::class);
|
||||
|
||||
|
@ -35,7 +35,7 @@ class EditableCountryDropdownField extends EditableFormField
|
||||
|
||||
public function getFormField()
|
||||
{
|
||||
$field = DropdownField::create($this->Name, $this->Title)
|
||||
$field = DropdownField::create($this->Name, $this->Title ?: false)
|
||||
->setSource(i18n::getData()->getCountries())
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(EditableDropdown::class);
|
||||
|
@ -58,7 +58,7 @@ class EditableDateField extends EditableFormField
|
||||
? DBDatetime::now()->Format('Y-m-d')
|
||||
: $this->Default;
|
||||
|
||||
$field = FormField::create($this->Name, $this->Title, $defaultValue)
|
||||
$field = FormField::create($this->Name, $this->Title ?: false, $defaultValue)
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(EditableFormField::class);
|
||||
|
||||
|
@ -60,7 +60,7 @@ class EditableDropdown extends EditableMultipleOptionField
|
||||
*/
|
||||
public function getFormField()
|
||||
{
|
||||
$field = DropdownField::create($this->Name, $this->Title, $this->getOptionsMap())
|
||||
$field = DropdownField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(__CLASS__);
|
||||
|
||||
|
@ -30,7 +30,7 @@ class EditableEmailField extends EditableFormField
|
||||
|
||||
public function getFormField()
|
||||
{
|
||||
$field = EmailField::create($this->Name, $this->Title, $this->Default)
|
||||
$field = EmailField::create($this->Name, $this->Title ?: false, $this->Default)
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(EditableFormField::class);
|
||||
|
||||
|
@ -97,7 +97,7 @@ class EditableFileField extends EditableFormField
|
||||
|
||||
public function getFormField()
|
||||
{
|
||||
$field = FileField::create($this->Name, $this->Title)
|
||||
$field = FileField::create($this->Name, $this->Title ?: false)
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(__CLASS__);
|
||||
|
||||
|
@ -68,7 +68,7 @@ class EditableFormHeading extends EditableFormField
|
||||
|
||||
public function getFormField()
|
||||
{
|
||||
$labelField = HeaderField::create('userforms-header', $this->Title)
|
||||
$labelField = HeaderField::create('userforms-header', $this->Title ?: false)
|
||||
->setHeadingLevel($this->Level);
|
||||
$labelField->addExtraClass('FormHeading');
|
||||
$labelField->setAttribute('data-id', $this->Name);
|
||||
|
@ -54,7 +54,7 @@ class EditableMemberListField extends EditableFormField
|
||||
}
|
||||
|
||||
$members = Member::map_in_groups($this->GroupID);
|
||||
$field = DropdownField::create($this->Name, $this->Title, $members);
|
||||
$field = DropdownField::create($this->Name, $this->Title ?: false, $members);
|
||||
$this->doUpdateFormField($field);
|
||||
return $field;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class EditableNumericField extends EditableFormField
|
||||
*/
|
||||
public function getFormField()
|
||||
{
|
||||
$field = NumericField::create($this->Name, $this->Title, $this->Default)
|
||||
$field = NumericField::create($this->Name, $this->Title ?: false, $this->Default)
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(EditableFormField::class)
|
||||
->addExtraClass('number');
|
||||
|
@ -35,7 +35,7 @@ class EditableRadioField extends EditableMultipleOptionField
|
||||
|
||||
public function getFormField()
|
||||
{
|
||||
$field = OptionsetField::create($this->Name, $this->Title, $this->getOptionsMap())
|
||||
$field = OptionsetField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
|
||||
->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder')
|
||||
->setTemplate('SilverStripe\\UserForms\\FormField\\UserFormsOptionSetField');
|
||||
|
||||
|
@ -128,12 +128,12 @@ class EditableTextField extends EditableFormField
|
||||
public function getFormField()
|
||||
{
|
||||
if ($this->Rows > 1) {
|
||||
$field = TextareaField::create($this->Name, $this->Title, $this->Default)
|
||||
$field = TextareaField::create($this->Name, $this->Title ?: false, $this->Default)
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(str_replace('EditableTextField', 'EditableTextareaField', __CLASS__))
|
||||
->setRows($this->Rows);
|
||||
} else {
|
||||
$field = TextField::create($this->Name, $this->Title, $this->Default)
|
||||
$field = TextField::create($this->Name, $this->Title ?: false, $this->Default)
|
||||
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
||||
->setTemplate(EditableFormField::class);
|
||||
}
|
||||
|
@ -89,7 +89,9 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
||||
|
||||
// check to see if the user was redirected (301)
|
||||
$this->assertEquals($response->getStatusCode(), 302);
|
||||
$this->assertStringEndsWith('finished#uff', $response->getHeader('Location'));
|
||||
$location = $response->getHeader('Location');
|
||||
$this->assertContains('finished', $location);
|
||||
$this->assertStringEndsWith('#uff', $location);
|
||||
|
||||
// check that multiple email addresses are supported in to and from
|
||||
$this->assertEmailSent(
|
||||
|
@ -18,4 +18,12 @@ class EditableCheckboxGroupFieldTest extends SapphireTest
|
||||
$checkboxGroup = $this->objFromFixture(EditableCheckboxGroupField::class, 'checkbox-group');
|
||||
$this->assertSame(UserFormsCheckboxSetField::class, $checkboxGroup->getFormField()->getTemplate());
|
||||
}
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableCheckboxGroupField $field */
|
||||
$field = EditableCheckboxGroupField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
||||
|
17
tests/Model/EditableFormField/EditableCheckboxTest.php
Normal file
17
tests/Model/EditableFormField/EditableCheckboxTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckbox;
|
||||
|
||||
class EditableCheckboxTest extends SapphireTest
|
||||
{
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableCheckbox $field */
|
||||
$field = EditableCheckbox::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
@ -13,4 +13,12 @@ class EditableCountryDropdownFieldTest extends SapphireTest
|
||||
|
||||
$this->assertContains('/images/editabledropdown.png', $field->getIcon());
|
||||
}
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableCountryDropdownField $field */
|
||||
$field = EditableCountryDropdownField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
||||
|
17
tests/Model/EditableFormField/EditableDateFieldTest.php
Normal file
17
tests/Model/EditableFormField/EditableDateFieldTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableDateField;
|
||||
|
||||
class EditableDateFieldTest extends SapphireTest
|
||||
{
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableDateField $field */
|
||||
$field = EditableDateField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
@ -36,4 +36,12 @@ class EditableDropdownTest extends SapphireTest
|
||||
$alternateDropdown->write();
|
||||
$this->assertEquals($formField->getEmptyString(), '');
|
||||
}
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableDropdown $field */
|
||||
$field = EditableDropdown::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
||||
|
17
tests/Model/EditableFormField/EditableEmailFieldTest.php
Normal file
17
tests/Model/EditableFormField/EditableEmailFieldTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
||||
|
||||
class EditableEmailFieldTest extends SapphireTest
|
||||
{
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableEmailField $field */
|
||||
$field = EditableEmailField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
17
tests/Model/EditableFormField/EditableFieldGroupTest.php
Normal file
17
tests/Model/EditableFormField/EditableFieldGroupTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
|
||||
|
||||
class EditableFieldGroupTest extends SapphireTest
|
||||
{
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableFieldGroup $field */
|
||||
$field = EditableFieldGroup::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
@ -64,4 +64,12 @@ class EditableFileFieldTest extends SapphireTest
|
||||
$formField = $fileField->getFormField();
|
||||
$this->assertEquals($formField->getValidator()->getAllowedMaxFileSize(), 262144);
|
||||
}
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableFileField $field */
|
||||
$field = EditableFileField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
||||
|
17
tests/Model/EditableFormField/EditableFormHeadingTest.php
Normal file
17
tests/Model/EditableFormField/EditableFormHeadingTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
|
||||
|
||||
class EditableFormHeadingTest extends SapphireTest
|
||||
{
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableFormHeading $field */
|
||||
$field = EditableFormHeading::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
17
tests/Model/EditableFormField/EditableFormStepTest.php
Normal file
17
tests/Model/EditableFormField/EditableFormStepTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
|
||||
|
||||
class EditableFormStepTest extends SapphireTest
|
||||
{
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableFormStep $field */
|
||||
$field = EditableFormStep::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableMemberListField;
|
||||
|
||||
class EditableMemberListFieldTest extends SapphireTest
|
||||
{
|
||||
protected static $fixture_file = 'EditableMemberListFieldTest.yml';
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableMemberListField $field */
|
||||
$field = EditableMemberListField::create();
|
||||
$field->GroupID = $this->idFromFixture(Group::class, 'a_group');
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
SilverStripe\Security\Group:
|
||||
a_group:
|
||||
Title: A security group
|
17
tests/Model/EditableFormField/EditableNumericFieldTest.php
Normal file
17
tests/Model/EditableFormField/EditableNumericFieldTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableNumericField;
|
||||
|
||||
class EditableNumericFieldTest extends SapphireTest
|
||||
{
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableNumericField $field */
|
||||
$field = EditableNumericField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
@ -3,8 +3,6 @@
|
||||
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckboxGroupField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField;
|
||||
|
||||
class EditableRadioFieldTest extends SapphireTest
|
||||
@ -22,4 +20,12 @@ class EditableRadioFieldTest extends SapphireTest
|
||||
$radio->getFormField()->getTemplate()
|
||||
);
|
||||
}
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableRadioField $field */
|
||||
$field = EditableRadioField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
||||
|
@ -20,4 +20,16 @@ class EditableTextFieldTest extends SapphireTest
|
||||
$this->assertInstanceOf(DropdownField::class, $autocompleteField);
|
||||
$this->assertEquals(['foo' => 'foo'], $autocompleteField->getSource());
|
||||
}
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableTextField $field */
|
||||
$field = EditableTextField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$field->Rows = 1;
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
|
||||
$field->Rows = 3;
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
||||
|
@ -86,9 +86,6 @@ class EditableFormFieldTest extends FunctionalTest
|
||||
$this->assertEquals(0, $checkbox->EffectiveDisplayRules()->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers EditableOption::getValue
|
||||
*/
|
||||
public function testEditableOptionEmptyValue()
|
||||
{
|
||||
$option = $this->objFromFixture(EditableOption::class, 'option-1');
|
||||
|
Loading…
Reference in New Issue
Block a user