ENHANCEMENT: Add autocomplete to EditableTextField

* Fixes #526 (autocomplete attributes)

adds ability for text fields to store additional html5 autocomplete
attributes, attributes are per text field and populated from a dropdown
list from the html5 specification. (Credit card and password
autocomplete values omitted as should user defined forms be used to
collect this information?)

* Options moved to config

moved array of auto complete values out to config option as recommended

* Clarify function

updated name, and added description to make more obvious what function
is for normal users

* added translation for field names

along with some localisation for DE/EN/ES/FR/IT/PL/RU languages

* formatting changes and argument removal

formatted array as chopped list, and remove argument that wasn’t
required.

* ADHD kicking in

consistency changes.
This commit is contained in:
Elliot Goode 2016-12-13 21:12:46 +00:00 committed by Damian Mooyman
parent 8dc89fd2f9
commit d0bf02d25f
8 changed files with 66 additions and 1 deletions

View File

@ -14,11 +14,42 @@ class EditableTextField extends EditableFormField
private static $plural_name = 'Text Fields';
private static $autocomplete_options = array(
'off' => 'Off',
'on' => 'On',
'name' => 'Full name',
'honorific-prefix' => 'Prefix or title',
'given-name' => 'First name',
'additional-name' => 'Additional name',
'family-name' => 'Family name',
'honorific-suffix' => 'Suffix (e.g Jr.)',
'nickname' => 'Nickname',
'email' => 'Email',
'organization-title' => 'Job title',
'organization' => 'Organization',
'street-address' => 'Street address',
'address-line1' => 'Address line 1',
'address-line2' => 'Address line 2',
'address-line3' => 'Address line 3',
'address-level1' => 'Address level 1',
'address-level2' => 'Address level 2',
'address-level3' => 'Address level 3',
'address-level4' => 'Address level 4',
'country' => 'Country',
'country-name' => 'Country name',
'postal-code' => 'Postal code',
'bday' => 'Birthday',
'sex' => 'Gender identity',
'tel' => 'Telephone number',
'url' => 'Home page'
);
private static $db = array(
'MinLength' => 'Int',
'MaxLength' => 'Int',
'Rows' => 'Int(1)',
'Placeholder' => 'Varchar(255)'
'Placeholder' => 'Varchar(255)',
'Autocomplete' => 'Varchar(255)'
);
private static $defaults = array(
@ -46,6 +77,19 @@ class EditableTextField extends EditableFormField
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
)
);
$fields->addFieldToTab(
'Root.Main',
DropdownField::create(
'Autocomplete',
_t('EditableTextField.AUTOCOMPLETE', 'Autocomplete'),
$this->config()->get('autocomplete_options')
)->setDescription(_t(
'EditableTextField.AUTOCOMPLETE_DESCRIPTION',
'Supported browsers will attempt to populate this field automatically with the users information, use to set the value populated'
))
);
});
return parent::getCMSFields();
@ -116,5 +160,10 @@ class EditableTextField extends EditableFormField
if ($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
if ($this->Autocomplete) {
$field->setAttribute('autocomplete', $this->Autocomplete);
}
}
}

View File

@ -108,6 +108,8 @@ de_DE:
PLURALNAME: 'Radio-Buttons'
SINGULARNAME: 'Radio-Button'
EditableTextField:
AUTOCOMPLETE: 'Automatisch vervollständigen'
AUTOCOMPLETE_DESCRIPTION: 'Unterstützte Browser versuchen, dieses Feld automatisch mit den Benutzerinformationen zu füllen, verwenden, um den gefüllten Wert festzulegen'
NUMBERROWS: 'Anzahl der Zeilen'
PLACEHOLDER: Platzhalter
PLURALNAME: 'Textfelder'

View File

@ -140,6 +140,8 @@ en:
PLURALNAME: 'Radio Groups'
SINGULARNAME: 'Radio Group'
EditableTextField:
AUTOCOMPLETE: 'Autocomplete'
AUTOCOMPLETE_DESCRIPTION: 'Supported browsers will attempt to populate this field automatically with the users information, use to set the value populated'
NUMBERROWS: 'Number of rows'
NUMBERROWS_DESCRIPTION: 'Fields with more than one row will be generated as a textarea'
PLACEHOLDER: Placeholder

View File

@ -106,6 +106,8 @@ es_ES:
PLURALNAME: 'Opciones editables'
SINGULARNAME: 'Opciones editables'
EditableTextField:
AUTOCOMPLETE: 'Autocompletar'
AUTOCOMPLETE_DESCRIPTION: 'Los navegadores compatibles intentarán rellenar este campo automáticamente con la información de los usuarios, usarla para establecer el valor poblado'
NUMBERROWS: 'Cantidad de filas'
PLURALNAME: 'Campos de texto'
SINGULARNAME: 'Campo de texto'

View File

@ -60,6 +60,9 @@ fr_FR:
DELETE: 'Remove this option'
DRAG: 'Drag to rearrange order of options'
LOCKED: 'These fields cannot be modified'
EditableTextField:
AUTOCOMPLETE: 'Autocomplétion'
AUTOCOMPLETE_DESCRIPTION: 'Les navigateurs pris en charge essaieront de remplir automatiquement ce champ avec les informations des utilisateurs, utilisez pour définir la valeur remplie'
Form:
FIELDISREQUIRED: '%s is required'
SubmittedFileField:

View File

@ -140,6 +140,8 @@ it:
PLURALNAME: 'Gruppi di pulsanti a scelta singola'
SINGULARNAME: 'Gruppo di pulsanti a scelta singola'
EditableTextField:
AUTOCOMPLETE: 'completamento automatico'
AUTOCOMPLETE_DESCRIPTION: 'I browser supportati cercheranno di popolare automaticamente questo campo con l'informazione agli utenti, usare per impostare il valore popolata'
NUMBERROWS: 'Numero di righe'
NUMBERROWS_DESCRIPTION: 'Campi con più di una riga verranno generati come area testo'
PLACEHOLDER: Segnaposto

View File

@ -103,6 +103,8 @@ pl_PL:
PLURALNAME: 'Pola wyboru'
SINGULARNAME: 'Pole wyboru'
EditableTextField:
AUTOCOMPLETE: 'autouzupełnienie'
AUTOCOMPLETE_DESCRIPTION: 'Obsługiwane przeglądarki podejmie próbę wypełnienia tego pola automatycznie z informacji użytkowników, należy ustawić wartość zaludnionych'
NUMBERROWS: 'Liczba wierszy'
PLURALNAME: 'Pola tekstowe'
SINGULARNAME: 'Pole tekstowe'

View File

@ -60,6 +60,9 @@ ru_RU:
DELETE: 'Remove this option'
DRAG: 'Drag to rearrange order of options'
LOCKED: 'These fields cannot be modified'
EditableTextField:
AUTOCOMPLETE: 'автозаполнения'
AUTOCOMPLETE_DESCRIPTION: 'Поддерживаемые браузеры будут пытаться автоматически заполнять это поле с информацией пользователей, используйте для установки значения населенную'
Form:
FIELDISREQUIRED: '%s is required'
SubmittedFileField: