Skip to content

Commit

Permalink
Updated based on feedback (incompleted)
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Feb 14, 2017
1 parent 029a8b9 commit 6e08a18
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 366 deletions.
7 changes: 1 addition & 6 deletions docs/en/02_Developer_Guides/03_Forms/01_Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ Each individual [api:FormField] instance is responsible for validating the submi

Subclasses of `FormField` can define their own version of `validate` to provide custom validation rules such as the
above example with the `Email` validation. The `validate` method on `FormField` takes a single argument of the current
`Validator` instance.

<div class="notice" markdown="1">
The data value of the `FormField` submitted is not passed into validate. It is stored in the `value` property through
the `setValue` method.
</div>
`Validator` instance.

```php
public function validate($validator)
Expand Down
48 changes: 20 additions & 28 deletions docs/en/02_Developer_Guides/03_Forms/Field_types/02_DateField.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ summary: How to format and use the DateField class.

# DateField

This `FormField` subclass lets you display an editable date, either in a single text input field, or in three separate
fields for day, month and year. It also provides a calendar date picker.
This `FormField` subclass lets you display an editable date, in a single text input field.
It also provides a calendar date picker.

The following example will add a simple DateField to your Page, allowing you to enter a date manually.

Expand Down Expand Up @@ -33,14 +33,14 @@ The following example will add a simple DateField to your Page, allowing you to

## Custom Date Format

A custom date format for a [api:DateField] can be provided through `setConfig`.
A custom date format for a [api:DateField] can be provided through `setDateFormat`.

:::php
// will display a date in the following format: 31-06-2012
DateField::create('MyDate')->setDateFormat('dd-MM-yyyy');

<div class="info" markdown="1">
The formats are based on [Zend_Date constants](http://framework.zend.com/manual/1.12/en/zend.date.constants.html).
The formats are based on [CLDR format](http://userguide.icu-project.org/formatparse/datetime).
</div>


Expand All @@ -51,19 +51,16 @@ strtotime()).

:::php
DateField::create('MyDate')
->setConfig('min', '-7 days')
->setConfig('max', '2012-12-31')
->setMinDate('-7 days')
->setMaxDate'2012-12-31')
## Separate Day / Month / Year Fields

The following setting will display your DateField as three input fields for day, month and year separately. HTML5
placeholders 'day', 'month' and 'year' are enabled by default.
To display separate input fields for day, month and year separately you can use the `DateFieldSeparated` subclass`.
HTML5 placeholders 'day', 'month' and 'year' are enabled by default.

:::php
DateField::create('MyDate')
->setConfig('dmyfields', true)
->setConfig('dmyseparator', '/') // set the separator
->setConfig('dmyplaceholders', 'true'); // enable HTML 5 Placeholders
DateFieldSeparated::create('MyDate');

<div class="alert" markdown="1">
Any custom date format settings will be ignored.
Expand All @@ -75,10 +72,13 @@ The following setting will add a Calendar to a single DateField, using the jQuer

:::php
DateField::create('MyDate')
->setConfig('showcalendar', true);
->setShowCalendar(true);

The jQuery date picker will support most custom locale formats (if left as default).
If setting an explicit date format via setDateFormat() then the below table of supported
characters should be used.

The jQuery DatePicker doesn't support every constant available for `Zend_Date`. If you choose to use the calendar, the
following constants should at least be safe:
It is recommended to use numeric format, as `MMM` or `MMMM` month names may not always pass validation.

Constant | xxxxx
-------- | -----
Expand All @@ -94,15 +94,6 @@ y | year (4 digits)
yy | year (2 digits)
yyyy | year (4 digits)

Unfortunately the day- and monthname values in Zend Date do not always match those in the existing jQuery UI locale
files, so constants like `EEE` or `MMM`, for day and month names could break validation. To fix this we had to slightly
alter the jQuery locale files, situated in */framework/thirdparty/jquery-ui/datepicker/i18n/*, to match Zend_Date.

<div class="info">
At this moment not all locale files may be present. If a locale file is missing, the DatePicker calendar will fallback
to 'yyyy-MM-dd' whenever day - and/or monthnames are used. After saving, the correct format will be displayed.
</div>

## Formatting Hints

It's often not immediate apparent which format a field accepts, and showing the technical format (e.g. `HH:mm:ss`) is
Expand All @@ -113,13 +104,14 @@ field description as an example.
$dateField = DateField::create('MyDate');

// Show long format as text below the field
$dateField->setDescription(sprintf(
_t('FormField.Example', 'e.g. %s', 'Example format'),
Convert::raw2xml(Zend_Date::now()->toString($dateField->getConfig('dateformat')))
$dateField->setDescription(_t(
'FormField.Example',
'e.g. {format}',
[ 'format' => $dateField->getDateFormat() ]
));

// Alternatively, set short format as a placeholder in the field
$dateField->setAttribute('placeholder', $dateField->getConfig('dateformat'));
$dateField->setAttribute('placeholder', $dateField->getDateFormat());

<div class="notice" markdown="1">
Fields scaffolded through [api:DataObject::scaffoldCMSFields()] automatically have a description attached to them.
Expand Down
60 changes: 36 additions & 24 deletions docs/en/04_Changelogs/4.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ specific functions.
by the array key, or the `class` parameter value.
* Uniqueness checks for `File.Name` is performed on write only (not in `setName()`)
* Created `Resettable` interface to better declare objects which should be reset between tests.
* Added a server requirement for the php-intl extension (shipped by default with most PHP distributions)
* Replaced Zend_Date and Zend_Locale with the php-intl extension.
* Consistently use CLDR date formats (rather than a mix of CLDR and date() formats)

#### <a name="overview-general-removed"></a>General and Core Removed API

Expand Down Expand Up @@ -1052,17 +1055,21 @@ A very small number of methods were chosen for deprecation, and will be removed
* `ChangeSet` and `ChangeSetItem` have been added for batch publishing of versioned dataobjects.
* `DataObject.table_name` config can now be used to customise the database table for any record.
* `DataObjectSchema` class added to assist with mapping between classes and tables.
* `DBMoney` values are now treated as empty only Amount is null. Values without Currency
will be formatted in the default locale.
* `DBMoney` values are now treated as empty only if `Amount` field is null. If an `Amount` value
is provided without a `Currency` specified, it will be formatted as per the current locale.

The below methods have been added or had their functionality updated to `DBDate`, `DBTime` and `DBDatetime`
* `getTimestamp()` added to get the respective date / time as unix timestamp (seconds since 1970-01-01)
* `Format()` method now use CLDR format strings, rather than PHP format strings.
See http://userguide.icu-project.org/formatparse/datetime.
* `Format()` method now use [CLDR format strings](http://userguide.icu-project.org/formatparse/datetime),
rather than [PHP format string](http://php.net/manual/en/function.date.php).
E.g. `d/m/Y H:i:s` (php format) should be replaced with to `dd/MM/y HH:mm:ss` (CLDR format).
* getISOFormat() added which returns the standard date/time ISO 8601 pattern in CLDR format.
* Dates passed in m/d/y format will now raise a notice but will be parsed.
Dates passed to constructors should follow ISO 8601 (y-m-d).
* 2-digit years will raise a notice.
* `setValue` method is now a lot more restrictive, and expects dates and times to be passed in
ISO 8601 format (y-MM-dd) or (HH:mm:ss). Certain date formats will attempt to parse with
the below restrictions:
- Dates passed in with leading months (MM/dd/y format) will now raise a notice but will be parsed.
Dates passed to constructors should follow ISO 8601 (y-MM-dd).
- 2-digit years will raise a notice, since they are ambiguous without additional formatting hints.
* `FormatFromSettings` will default to `Nice()` format if no member is logged in.
* `Nice`, `Long` and `Full` methods will now follow standard formatting rules for the
current locale, rather than pre-defined formats.
Expand All @@ -1071,7 +1078,6 @@ The below methods have been added or had their functionality updated to `DBDate`

`DBTime` specific changes:
* Added `DBTime::FormatFromSettings`
* Added `DBTime::Nice12`

#### <a name="overview-orm-removed"></a>ORM Removed API

Expand Down Expand Up @@ -1115,7 +1121,9 @@ The below methods have been added or had their functionality updated to `DBDate`
- `days_between`
* `nice_format` has been removed from `DBDate` / `DBTime` / `DBDatetime` has been removed in favour of
locale-specific formatting for Nice()
* Removed `DBTime::TwelveHour`
* Removed several `DBTime` methods:
- `TwelveHour`
- `Nice24`
* Removed some `DBMoney` methods due to lack of support in php-intl.
- `NiceWithShortname`
- `NiceWithName`
Expand Down Expand Up @@ -1235,6 +1243,9 @@ The following filesystem synchronisation methods and tasks are also removed
* Introduced `AssetAdmin\Forms\UploadField` as a react-friendly version of UploadField. This may also
be used in normal entwine forms for managing files in a similar way to UploadField. However, this
does not support inline editing of files.
* Added method `FormField::setSubmittedValue($value, $data)` to process input submitted from form
submission, in contrast to `FormField::setValue($value, $data)` which is intended to load its
value from the ORM. The second argument to setValue() has been added.

The following methods and properties on `Requirements_Backend` have been renamed:

Expand Down Expand Up @@ -1320,6 +1331,7 @@ New `DatetimeField` methods replace `getConfig()` / `setConfig()`:
* `getTimezone()` / `setTimezone()`
* `getDateTimeOrder()` / `setDateTimeOrder()`
* `getLocale()` / `setLocale()`
* `datavaluefield` config is removed as internal data value is now fixed to ISO 8601 format

New `DateField` methods replace `getConfig()` / `setConfig()`:

Expand All @@ -1328,9 +1340,9 @@ New `DateField` methods replace `getConfig()` / `setConfig()`:
* `getMinDate()` / `setMinDate()`
* `getMaxDate()` / `setMaxDate()`
* `getPlaceholders()` / `setPlaceholders()`
* `getSeparateDMYFields()` / `setSeparateDMYFields()`
* `getClientLocale` / `setClientLocale`
* `getLocale()` / `setLocale()`
* option `dmyfields` is now superceded with an `DateFieldSeparated` class

New `TimeField` methods replace `getConfig()` / `setConfig()`

Expand Down Expand Up @@ -1383,20 +1395,20 @@ New `TimeField` methods replace `getConfig()` / `setConfig()`
for all DataObject subclasses, rather than just the basename without namespace.
* i18n key for locale-respective pluralisation rules added as '.PLURALS'. These can be configured
within yaml in array format as per [ruby i18n pluralization rules](http://guides.rubyonrails.org/i18n.html#pluralization).
* `i18n.all_locales` config moved to `Locales.locales`
* `i18n.common_languages` config moved to `Locales.languages`
* `i18n.likely_subtags` config moved to `Locales.likely_subtags`
* `i18n.tinymce_lang` config moved to `TinyMCEConfig.tinymce_lang`
* `i18n::get_tinymce_lang()` moved to `TinyMCEConfig::get_tinymce_lang()`
* `i18n::get_locale_from_lang()` moved to `Locales::localeFromLang()`
* `i18n::get_lange_from_locale()` moved to `Locales::langFromLocale()`
* `i18n::validate_locale()` moved to `Locales::validate()`
* `i18n::get_common_languages()` moved to `Locales::getLanguages()`
* `i18n::get_locale_name()` moved to `Locales::localeName()`
* `i18n::get_language_name()` moved to `Locales::languageName()`
* `i18n.module_priority` config moved to `Sources.module_priority`
* `i18n::get_owner_module()` moved to `ClassManifest::getOwnerModule()`
* `i18n::get_existing_translations()` moved to `Sources::getKnownLocales()`
* `i18n.all_locales` config moved to `SilverStripe\i18n\Data\Locales.locales`
* `i18n.common_languages` config moved to `SilverStripe\i18n\Data\Locales.languages`
* `i18n.likely_subtags` config moved to `SilverStripe\i18n\Data\Locales.likely_subtags`
* `i18n.tinymce_lang` config moved to `SilverStripe\Forms\HTMLEditor\TinyMCEConfig.tinymce_lang`
* `i18n::get_tinymce_lang()` moved to `SilverStripe\Forms\HTMLEditor\TinyMCEConfig::get_tinymce_lang()`
* `i18n::get_locale_from_lang()` moved to `SilverStripe\i18n\Data\Locales::localeFromLang()`
* `i18n::get_lange_from_locale()` moved to `SilverStripe\i18n\Data\Locales::langFromLocale()`
* `i18n::validate_locale()` moved to `SilverStripe\i18n\Data\Locales::validate()`
* `i18n::get_common_languages()` moved to `SilverStripe\i18n\Data\Locales::getLanguages()`
* `i18n::get_locale_name()` moved to `SilverStripe\i18n\Data\Locales::localeName()`
* `i18n::get_language_name()` moved to `SilverStripe\i18n\Data\Locales::languageName()`
* `i18n.module_priority` config moved to `SilverStripe\i18n\Data\Sources.module_priority`
* `i18n::get_owner_module()` moved to `SilverStripe\Core\Manifest\ClassManifest::getOwnerModule()`
* `i18n::get_existing_translations()` moved to `SilverStripe\i18n\Data\Sources::getKnownLocales()`

#### <a name="overview-i18n-removed"></a>i18n API Removed API

Expand Down
Loading

0 comments on commit 6e08a18

Please sign in to comment.