mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #6894 from open-sausages/pulls/4.0/6741-decouple-schema-type-and-type
Pulls/4.0/6741 decouple schema type and type
This commit is contained in:
commit
ff35baaeab
@ -94,6 +94,8 @@ class DateField extends TextField
|
||||
*/
|
||||
protected $clientLocale = null;
|
||||
|
||||
protected $inputType = 'date';
|
||||
|
||||
/**
|
||||
* Min date
|
||||
*
|
||||
@ -283,9 +285,10 @@ class DateField extends TextField
|
||||
$attributes['lang'] = i18n::convert_rfc1766($this->getLocale());
|
||||
|
||||
if ($this->getHTML5()) {
|
||||
$attributes['type'] = 'date';
|
||||
$attributes['min'] = $this->getMinDate();
|
||||
$attributes['max'] = $this->getMaxDate();
|
||||
} else {
|
||||
$attributes['type'] = 'text';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
@ -30,6 +30,8 @@ class DatetimeField extends TextField
|
||||
*/
|
||||
protected $locale = null;
|
||||
|
||||
protected $inputType = 'datetime-local';
|
||||
|
||||
/**
|
||||
* Min date time
|
||||
*
|
||||
@ -94,9 +96,10 @@ class DatetimeField extends TextField
|
||||
$attributes['lang'] = i18n::convert_rfc1766($this->getLocale());
|
||||
|
||||
if ($this->getHTML5()) {
|
||||
$attributes['type'] = 'datetime-local';
|
||||
$attributes['min'] = $this->internalToFrontend($this->getMinDatetime());
|
||||
$attributes['max'] = $this->internalToFrontend($this->getMaxDatetime());
|
||||
} else {
|
||||
$attributes['type'] = 'text';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
@ -7,6 +7,8 @@ namespace SilverStripe\Forms;
|
||||
*/
|
||||
class EmailField extends TextField
|
||||
{
|
||||
|
||||
protected $inputType = 'email';
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -15,19 +17,6 @@ class EmailField extends TextField
|
||||
return 'email text';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array_merge(
|
||||
parent::getAttributes(),
|
||||
array(
|
||||
'type' => 'email',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates for RFC 2822 compliant email addresses.
|
||||
*
|
||||
|
@ -47,6 +47,8 @@ class FileField extends FormField implements FileHandleField
|
||||
{
|
||||
use UploadReceiver;
|
||||
|
||||
protected $inputType = 'file';
|
||||
|
||||
/**
|
||||
* Flag to automatically determine and save a has_one-relationship
|
||||
* on the saved record (e.g. a "Player" has_one "PlayerImage" would
|
||||
@ -83,14 +85,6 @@ class FileField extends FormField implements FileHandleField
|
||||
return parent::Field($properties);
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
{
|
||||
return array_merge(
|
||||
parent::getAttributes(),
|
||||
array('type' => 'file')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataObject|DataObjectInterface $record
|
||||
*/
|
||||
|
@ -173,20 +173,23 @@ class FormAction extends FormField
|
||||
return 'action';
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
public function getInputType()
|
||||
{
|
||||
if (isset($this->attributes['type'])) {
|
||||
$type = $this->attributes['type'];
|
||||
return $this->attributes['type'];
|
||||
} else {
|
||||
$type = (isset($this->attributes['src'])) ? 'image' : 'submit';
|
||||
return (isset($this->attributes['src'])) ? 'image' : 'submit';
|
||||
}
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
{
|
||||
return array_merge(
|
||||
parent::getAttributes(),
|
||||
array(
|
||||
'disabled' => ($this->isReadonly() || $this->isDisabled()),
|
||||
'value' => $this->Title(),
|
||||
'type' => $type,
|
||||
'type' => $this->getInputType(),
|
||||
'title' => ($this->useButtonTag) ? $this->description : null,
|
||||
)
|
||||
);
|
||||
|
@ -89,6 +89,13 @@ class FormField extends RequestHandler
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
/**
|
||||
* This is INPUT's type attribute value.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $inputType = 'text';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -446,6 +453,16 @@ class FormField extends RequestHandler
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field input name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInputType()
|
||||
{
|
||||
return $this->inputType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field value.
|
||||
*
|
||||
@ -678,7 +695,7 @@ class FormField extends RequestHandler
|
||||
public function getAttributes()
|
||||
{
|
||||
$attributes = array(
|
||||
'type' => 'text',
|
||||
'type' => $this->getInputType(),
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->Value(),
|
||||
'class' => $this->extraClass(),
|
||||
@ -811,6 +828,20 @@ class FormField extends RequestHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field input type.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setInputType($type)
|
||||
{
|
||||
$this->inputType = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the container form.
|
||||
*
|
||||
@ -1499,7 +1530,8 @@ class FormField extends RequestHandler
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'id' => $this->ID(),
|
||||
'type' => $this->getSchemaDataType(),
|
||||
'type' => $this->getInputType(),
|
||||
'schemaType' => $this->getSchemaDataType(),
|
||||
'component' => $this->getSchemaComponent(),
|
||||
'holderId' => $this->HolderID(),
|
||||
'title' => $this->Title(),
|
||||
|
@ -10,6 +10,8 @@ class HiddenField extends FormField
|
||||
|
||||
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_HIDDEN;
|
||||
|
||||
protected $inputType = 'hidden';
|
||||
|
||||
/**
|
||||
* @param array $properties
|
||||
* @return string
|
||||
@ -39,19 +41,6 @@ class HiddenField extends FormField
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array_merge(
|
||||
parent::getAttributes(),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SmallFieldHolder($properties = array())
|
||||
{
|
||||
return $this->FieldHolder($properties);
|
||||
|
@ -15,6 +15,8 @@ class NumericField extends TextField
|
||||
|
||||
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_DECIMAL;
|
||||
|
||||
protected $inputType = 'number';
|
||||
|
||||
/**
|
||||
* Used to determine if the number given is in the correct format when validating
|
||||
*
|
||||
@ -170,9 +172,11 @@ class NumericField extends TextField
|
||||
{
|
||||
$attributes = parent::getAttributes();
|
||||
if ($this->getHTML5()) {
|
||||
$attributes['type'] = 'number';
|
||||
$attributes['step'] = $this->getStep();
|
||||
} else {
|
||||
$attributes['type'] = 'text';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ class PasswordField extends TextField
|
||||
*/
|
||||
private static $autocomplete;
|
||||
|
||||
protected $inputType = 'password';
|
||||
|
||||
/**
|
||||
* Returns an input field.
|
||||
*
|
||||
@ -42,9 +44,7 @@ class PasswordField extends TextField
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
$attributes = array(
|
||||
'type' => 'password',
|
||||
);
|
||||
$attributes = array();
|
||||
|
||||
$autocomplete = $this->config()->get('autocomplete');
|
||||
|
||||
|
@ -30,6 +30,8 @@ class PopoverField extends FieldGroup
|
||||
*/
|
||||
protected $popoverTitle = null;
|
||||
|
||||
protected $inputType = null;
|
||||
|
||||
/**
|
||||
* Placement of the popup box, relative to the element triggering it.
|
||||
* Valid values: bottom, top, left, right.
|
||||
|
@ -28,6 +28,8 @@ class TimeField extends TextField
|
||||
*/
|
||||
protected $locale = null;
|
||||
|
||||
protected $inputType = 'time';
|
||||
|
||||
/**
|
||||
* Override time format. If empty will default to that used by the current locale.
|
||||
*
|
||||
@ -224,8 +226,8 @@ class TimeField extends TextField
|
||||
{
|
||||
$attributes = parent::getAttributes();
|
||||
|
||||
if ($this->getHTML5()) {
|
||||
$attributes['type'] = 'time';
|
||||
if (!$this->getHTML5()) {
|
||||
$attributes['type'] = 'text';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
@ -16,7 +16,8 @@
|
||||
{
|
||||
"id": "Form_TestForm_Name",
|
||||
"name": "Name",
|
||||
"type": "Text",
|
||||
"type": "text",
|
||||
"schemaType": "Text",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_Name_Holder",
|
||||
"title": "Name",
|
||||
@ -35,7 +36,8 @@
|
||||
{
|
||||
"id": "Form_TestForm_SecurityID",
|
||||
"name": "SecurityID",
|
||||
"type": "Hidden",
|
||||
"type": "hidden",
|
||||
"schemaType": "Hidden",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_SecurityID_Holder",
|
||||
"title": "Security ID",
|
||||
@ -57,7 +59,8 @@
|
||||
"id": "Form_TestForm_action_save",
|
||||
"title": "Save",
|
||||
"name": "action_save",
|
||||
"type": null,
|
||||
"type": "submit",
|
||||
"schemaType": null,
|
||||
"component": "FormAction",
|
||||
"holderId": "Form_TestForm_action_save_Holder",
|
||||
"source": null,
|
||||
@ -80,7 +83,8 @@
|
||||
"id": "Form_TestForm_action_cancel",
|
||||
"title": "Cancel",
|
||||
"name": "action_cancel",
|
||||
"type": null,
|
||||
"type": "submit",
|
||||
"schemaType": null,
|
||||
"component": "FormAction",
|
||||
"holderId": "Form_TestForm_action_cancel_Holder",
|
||||
"source": null,
|
||||
@ -103,7 +107,8 @@
|
||||
"id": "Form_TestForm_Moreoptions",
|
||||
"title": "More options",
|
||||
"name": "Moreoptions",
|
||||
"type": "Structural",
|
||||
"schemaType": "Structural",
|
||||
"type": null,
|
||||
"component": "PopoverField",
|
||||
"holderId": "Form_TestForm_Moreoptions_Holder",
|
||||
"source": null,
|
||||
@ -133,7 +138,8 @@
|
||||
"id": "Form_TestForm_action_publish",
|
||||
"title": "Publish record",
|
||||
"name": "action_publish",
|
||||
"type": null,
|
||||
"type": "submit",
|
||||
"schemaType": null,
|
||||
"component": "FormAction",
|
||||
"holderId": "Form_TestForm_action_publish_Holder",
|
||||
"source": null,
|
||||
@ -156,7 +162,8 @@
|
||||
"id": "Form_TestForm_action_archive",
|
||||
"title": "Archive",
|
||||
"name": "action_archive",
|
||||
"type": null,
|
||||
"type": "submit",
|
||||
"schemaType": null,
|
||||
"component": "FormAction",
|
||||
"holderId": "Form_TestForm_action_archive_Holder",
|
||||
"source": null,
|
||||
|
@ -16,7 +16,8 @@
|
||||
{
|
||||
"id": "Form_TestForm_SecurityID",
|
||||
"name": "SecurityID",
|
||||
"type": "Hidden",
|
||||
"type": "hidden",
|
||||
"schemaType": "Hidden",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_SecurityID_Holder",
|
||||
"title": "Security ID",
|
||||
@ -34,4 +35,4 @@
|
||||
}
|
||||
],
|
||||
"actions": []
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,8 @@
|
||||
{
|
||||
"name": "Name",
|
||||
"id": "Form_TestForm_Name",
|
||||
"type": "Text",
|
||||
"type": "text",
|
||||
"schemaType": "Text",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_Name_Holder",
|
||||
"title": "Name",
|
||||
@ -40,7 +41,8 @@
|
||||
{
|
||||
"name": "Date",
|
||||
"id": "Form_TestForm_Date",
|
||||
"type": "Date",
|
||||
"type": "date",
|
||||
"schemaType": "Date",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_Date_Holder",
|
||||
"title": "Date",
|
||||
@ -66,7 +68,8 @@
|
||||
{
|
||||
"name": "Number",
|
||||
"id": "Form_TestForm_Number",
|
||||
"type": "Decimal",
|
||||
"type": "number",
|
||||
"schemaType": "Decimal",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_Number_Holder",
|
||||
"title": "Number",
|
||||
@ -87,7 +90,8 @@
|
||||
{
|
||||
"name": "Money",
|
||||
"id": "Form_TestForm_Money",
|
||||
"type": "Text",
|
||||
"type": "text",
|
||||
"schemaType": "Text",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_Money_Holder",
|
||||
"title": "Money",
|
||||
@ -108,7 +112,8 @@
|
||||
{
|
||||
"name": "SecurityID",
|
||||
"id": "Form_TestForm_SecurityID",
|
||||
"type": "Hidden",
|
||||
"type": "hidden",
|
||||
"schemaType": "Hidden",
|
||||
"component": null,
|
||||
"holderId": "Form_TestForm_SecurityID_Holder",
|
||||
"title": "Security ID",
|
||||
@ -126,4 +131,4 @@
|
||||
}
|
||||
],
|
||||
"actions": []
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user