mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
FIX Allow editable form fields to have nullable titles rather than fallback to Name
This commit is contained in:
parent
d13bf1e0bc
commit
5cce5f5a17
@ -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);
|
||||
}
|
||||
|
@ -87,12 +87,4 @@ class EditableLiteralFieldTest extends SapphireTest
|
||||
'Actual literal field exists in composite field children'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAllowEmptyTitle()
|
||||
{
|
||||
/** @var EditableLiteralField $field */
|
||||
$field = EditableLiteralField::create();
|
||||
$field->Name = 'EditableFormField_123456';
|
||||
$this->assertEmpty($field->getFormField()->Title());
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,10 @@ class EditableTextFieldTest extends SapphireTest
|
||||
/** @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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user