Skip to content

Commit

Permalink
feat: Added CustomFormField autocomplete field to provide HTML auto…
Browse files Browse the repository at this point in the history
…complete hint
  • Loading branch information
ambroisemaupate committed Jul 2, 2024
1 parent aac6e4e commit 6b8c3e7
Show file tree
Hide file tree
Showing 7 changed files with 544 additions and 4 deletions.
31 changes: 31 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20240702205419.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240702205419 extends AbstractMigration
{
public function getDescription(): string
{
return 'Added autocomplete field to custom_form_fields table.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE custom_form_fields ADD autocomplete VARCHAR(18) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE custom_form_fields DROP autocomplete');
}
}
49 changes: 49 additions & 0 deletions lib/RoadizCoreBundle/src/Entity/CustomFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation as SymfonySerializer;
use RZ\Roadiz\Core\AbstractEntities\AbstractField;
use Symfony\Component\Validator\Constraints\Choice;

/**
* CustomFormField entities are used to create CustomForms with
Expand Down Expand Up @@ -74,6 +75,43 @@ class CustomFormField extends AbstractField
]
private bool $required = false;

/**
* @var string|null https://developer.mozilla.org/fr/docs/Web/HTML/Attributes/autocomplete
*/
#[
ORM\Column(name: "autocomplete", type: 'string', length:18, nullable: true),
Serializer\Groups(["custom_form"]),
SymfonySerializer\Groups(["custom_form"]),
Choice([
'off',
'name',
'honorific-prefix',
'honorific-suffix',
'given-name',
'additional-name',
'family-name',
'nickname',
'email',
'username',
'organization-title',
'organization',
'street-address',
'country',
'country-name',
'postal-code',
'bday',
'bday-day',
'bday-month',
'bday-year',
'sex',
'tel',
'tel-national',
'url',
'photo',
])
]
private ?string $autocomplete = null;

public function __construct()
{
parent::__construct();
Expand Down Expand Up @@ -133,6 +171,17 @@ public function setRequired(bool $required): CustomFormField
return $this;
}

public function getAutocomplete(): ?string
{
return $this->autocomplete;
}

public function setAutocomplete(?string $autocomplete): CustomFormField
{
$this->autocomplete = $autocomplete;
return $this;
}

/**
* @return string
*/
Expand Down
12 changes: 8 additions & 4 deletions lib/RoadizCoreBundle/src/Form/CustomFormsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
],
];

if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['attr']['placeholder'] = $field->getPlaceholder();
}

if ($field->getAutocomplete() !== null) {
$option['attr']['autocomplete'] = $field->getAutocomplete();
}

if ($field->isRequired()) {
$option['required'] = true;
$option['constraints'] = [
Expand All @@ -198,7 +202,7 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
$option["format"] = DateType::HTML5_FORMAT;
break;
case AbstractField::ENUM_T:
if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['placeholder'] = $field->getPlaceholder();
}
$option["choices"] = $this->getChoices($field);
Expand All @@ -212,7 +216,7 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
}
break;
case AbstractField::MULTIPLE_T:
if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['placeholder'] = $field->getPlaceholder();
}
$option["choices"] = $this->getChoices($field);
Expand Down Expand Up @@ -255,7 +259,7 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
break;
case AbstractField::COUNTRY_T:
$option["expanded"] = $field->isExpanded();
if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['placeholder'] = $field->getPlaceholder();
}
if (!empty($field->getDefaultValues())) {
Expand Down
140 changes: 140 additions & 0 deletions lib/RoadizRozierBundle/translations/custom-forms/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,146 @@
<target state="translated">2 year</target>
<note/>
</trans-unit>
<trans-unit xml:space="preserve" id="customForm.autocomplete">
<source>customForm.autocomplete</source>
<target state="translated">Auto-complete hint</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="customForm.autocomplete.help">
<source>customForm.autocomplete.help</source>
<target state="translated">Provides a specific hint to browsers and input helpers on the value to auto-complete for this field.</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.no_autocomplete">
<source>autocomplete.no_autocomplete</source>
<target state="translated">-- Undefined --</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.off">
<source>autocomplete.off</source>
<target state="translated">Do not auto-complete this field</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.name">
<source>autocomplete.name</source>
<target state="translated">Full name</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.honorific-prefix">
<source>autocomplete.honorific-prefix</source>
<target state="translated">Prefix or title, such as "Mrs.", "Mr.", "Miss", "Ms.", "Dr.", etc</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.honorific-suffix">
<source>autocomplete.honorific-suffix</source>
<target state="translated">Suffix, such as "Jr.", "B.Sc.", "PhD.", "MBASW", or "IV"</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.given-name">
<source>autocomplete.given-name</source>
<target state="translated">Given (or "first") name</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.additional-name">
<source>autocomplete.additional-name</source>
<target state="translated">Middle name</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.family-name">
<source>autocomplete.family-name</source>
<target state="translated">Family (or "last") name</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.nickname">
<source>autocomplete.nickname</source>
<target state="translated">Nickname or handle</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.email">
<source>autocomplete.email</source>
<target state="translated">Email address</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.username">
<source>autocomplete.username</source>
<target state="translated">Username or account name</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.organization-title">
<source>autocomplete.organization-title</source>
<target state="translated">Job title</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.organization">
<source>autocomplete.organization</source>
<target state="translated">Company or organization name</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.street-address">
<source>autocomplete.street-address</source>
<target state="translated">Street address</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.country">
<source>autocomplete.country</source>
<target state="translated">Country or territory code</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.country-name">
<source>autocomplete.country-name</source>
<target state="translated">Country or territory name</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.postal-code">
<source>autocomplete.postal-code</source>
<target state="translated">Postal (or ZIP) code</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.bday">
<source>autocomplete.bday</source>
<target state="translated">Birth date, as a full date</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.bday-day">
<source>autocomplete.bday-day</source>
<target state="translated">Day of the month of a birth date</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.bday-month">
<source>autocomplete.bday-month</source>
<target state="translated">Month of the year of a birth date</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.bday-year">
<source>autocomplete.bday-year</source>
<target state="translated">Year of a birth date</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.sex">
<source>autocomplete.sex</source>
<target state="translated">Gender identity</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.tel">
<source>autocomplete.tel</source>
<target state="translated">Full phone number, including the country code</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.tel-national">
<source>autocomplete.tel-national</source>
<target state="translated">Phone number without the country code component</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.url">
<source>autocomplete.url</source>
<target state="translated">A URL, as appropriate given the context of the form</target>
<note></note>
</trans-unit>
<trans-unit xml:space="preserve" id="autocomplete.photo">
<source>autocomplete.photo</source>
<target state="translated">URL of an image representing the contact information given in the form.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 6b8c3e7

Please sign in to comment.