Skip to content

Commit

Permalink
[Bugfix] Add all form fields to validation setup (#446)
Browse files Browse the repository at this point in the history
All existing input fields of billing address and
shipping address are now included in the validator
setup which influences the rendering of the
corresponding fields.

Solves #383, #445
  • Loading branch information
rintisch authored Mar 21, 2024
1 parent 9e72e20 commit c81d477
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,39 @@ plugin.tx_cart {
billingAddress {
fields {
salutation.validator = NotEmpty
title.validator = Empty
firstName.validator = NotEmpty
lastName.validator = NotEmpty
email.validator = NotEmpty
phone.validator = Empty
fax.validator = Empty
company.validator = Empty
taxIdentificationNumber.validator = Empty
street.validator = NotEmpty
streetNumber.validator = Empty
addition.validator = Empty
zip.validator = NotEmpty
city.validator = NotEmpty
country.validator = NotEmpty
}
}
shippingAddress {
fields {
salutation.validator = NotEmpty
title.validator = Empty
firstName.validator = NotEmpty
lastName.validator = NotEmpty
email.validator = NotEmpty
phone.validator = Empty
fax.validator = Empty
company.validator = Empty
taxIdentificationNumber.validator = Empty
street.validator = NotEmpty
streetNumber.validator = Empty
addition.validator = Empty
zip.validator = NotEmpty
city.validator = NotEmpty
country.validator = NotEmpty
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ plugin.tx_cart {
salutation {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.salutation.validator}
}
title {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.title.validator}
}
firstName {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.firstName.validator}
}
Expand All @@ -193,6 +196,12 @@ plugin.tx_cart {
fax {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.fax.validator}
}
company {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.company.validator}
}
taxIdentificationNumber {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.taxIdentificationNumber.validator}
}
street {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.street.validator}
}
Expand All @@ -208,13 +217,19 @@ plugin.tx_cart {
city {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.city.validator}
}
country {
validator = {$plugin.tx_cart.settings.validation.billingAddress.fields.country.validator}
}
}
}
shippingAddress {
fields {
salutation {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.salutation.validator}
}
title {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.title.validator}
}
firstName {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.firstName.validator}
}
Expand All @@ -230,6 +245,12 @@ plugin.tx_cart {
fax {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.fax.validator}
}
company {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.company.validator}
}
taxIdentificationNumber {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.taxIdentificationNumber.validator}
}
street {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.street.validator}
}
Expand All @@ -245,6 +266,9 @@ plugin.tx_cart {
city {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.city.validator}
}
country {
validator = {$plugin.tx_cart.settings.validation.shippingAddress.fields.country.validator}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
Validating and hiding fields
============================

Using this TypoScript configuration it is possible to change the validation and
rendering of fields of the billing and shipping address.

Using the below shown TypoScript configuration allows to change the validation
and rendering of fields of the billing and shipping address.
The partials for the display of the addresses evaluates this configuration.
It controls whether the fields are mandatory, optional or not rendered att all.
It controls whether the fields are mandatory, optional or not rendered at all.

.. TIP::
This way it is easily possible to unhide e.g the fields `streetNumber` or
`addition` (which is a field for additional address information) which are
already defined but hidden by default.

Have a look at all fields with the value `Empty` to see all available
fields.


.. code-block:: typoscript
:caption: EXT:cart/Configuration/TypoScript/setup.typoscript
Expand All @@ -21,31 +29,39 @@ It controls whether the fields are mandatory, optional or not rendered att all.
billingAddress {
fields {
salutation.validator = NotEmpty
title.validator = Empty
firstName.validator = NotEmpty
lastName.validator = NotEmpty
email.validator = NotEmpty
phone.validator = Empty
fax.validator = Empty
company.validator = Empty
taxIdentificationNumber.validator = Empty
street.validator = NotEmpty
streetNumber.validator = Empty
addition.validator = Empty
zip.validator = NotEmpty
city.validator = NotEmpty
country.validator = NotEmpty
}
}
shippingAddress {
fields {
salutation.validator = NotEmpty
title.validator = Empty
firstName.validator = NotEmpty
lastName.validator = NotEmpty
email.validator = NotEmpty
phone.validator = Empty
fax.validator = Empty
company.validator = Empty
taxIdentificationNumber.validator = Empty
street.validator = NotEmpty
streetNumber.validator = Empty
addition.validator = Empty
zip.validator = NotEmpty
city.validator = NotEmpty
country.validator = NotEmpty
}
}
}
Expand All @@ -68,6 +84,7 @@ Option `Not Empty`
* The input field is rendered with the attribute `required` set to `true`.

.. code-block:: typoscript
:caption: EXT:sitepackage/Configuration/TypoScript/constants.typoscript
plugin.tx_cart.settings.validation.billingAddress.fields {
salutation.validator = NotEmpty
Expand All @@ -82,6 +99,7 @@ Option `Empty`
* The server checks whether the field is empty.

.. code-block:: typoscript
:caption: EXT:sitepackage/Configuration/TypoScript/constants.typoscript
plugin.tx_cart.settings.validation.billingAddress.fields {
salutation.validator = Empty
Expand All @@ -96,7 +114,12 @@ This has the following consequences:
* The label of the field is rendered without a trailing "*".
* The input field is rendered without the attribute `required`.

.. IMPORTANT::
While the two configuration above can be made within the
`constants.typoscript` is this configuration done in `setup.typoscript`.

.. code-block:: typoscript
:caption: EXT:sitepackage/Configuration/TypoScript/setup.typoscript
plugin.tx_cart.settings.validation.billingAddress.fields {
# !!! It is necessary to remove the whole address field,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. include:: ../../Includes.txt

=========================================================
Breaking: #445 - Include all address fields in validation
=========================================================

See :issue:`445`

Description
===========

All fields which exists for the billing address and for the shipping address
are now included within the validation array in TypoScript. The fields
`title`, `company`, `taxIdentificationNumber` and `country` were not included.
Including those fields makes it easier and especially more logic to manage
the validation and visibility of those fields.

Affected Installations
======================

By default the fields `title`, `company` and `taxIdentificationNumber` will
not be rendered, the field country will be rendered and required.

Migration
=========

See :ref:`validating-and-hiding-fields` how to manage the visibility and
validation of address fields.

.. index:: Template, Frontend, TypoScript

0 comments on commit c81d477

Please sign in to comment.