Comments (3)
I didn't know about date formatting resulting in non-numbers 😮
I'd say you have more knowledge about this topic than me: may you open a PR with related new tests, and see if all other tests still pass?
from laminas-form.
@Slamdunk I didn't know, or suspected, either (been using php since 2001 😄 ). I always assumed that hours, minutes and seconds formatting options could only result in non-zerofilled and zerofilled int strings. At first I thought that the IntlDateFormatter was being used just for symmetry with the label (array value) formatter, to have a more elegant/consistent code. Curiosity made me try it with all avaiable locales... I haven't used selects for date/time inputs in years, but while creating a Plates extensions for laminas-form, I had to examine laminas-form-view-helpers related code more thoroughly. There is also another inconsistency. The year select element has both numeric keys (select-option-values) and values (select-option-labels). It should have intl-formatted values values.
There is only one test checking the formatted selects in es_CL
. We would need tests checking that all the <option value="">
parts only contain 2 or 4 digits strings and no other chars, allowing the presented label to be locale-formatted
<?php
// INSTALL libs
// $ composer require laminas/laminas-form
// $ composer require laminas/laminas-i18n
// $ composer require laminas/laminas-view
use Laminas\Form\ConfigProvider;
use Laminas\Form\Element\DateTimeSelect;
use Laminas\Form\View\Helper\FormDateTimeSelect;
use Laminas\View\Renderer\PhpRenderer;
$locale = 'ar';
//Locale::setDefault($locale);
//setlocale(LC_ALL, $locale);
ini_set('display_errors', 'true');
$__dir = __DIR__;
require "{$__dir}/vendor/autoload.php";
$view = new PhpRenderer();
$helperPluginManager = $view->getHelperPluginManager();
$viewHelperConfig = (new ConfigProvider())->getViewHelperConfig();
$helperPluginManager->configure($viewHelperConfig);
$view->setHelperPluginManager($helperPluginManager);
$formDateTimeSelect = new FormDateTimeSelect();
$formDateTimeSelect->setView($view);
$datetimeField = new DateTimeSelect('createdAt');
$html = $formDateTimeSelect(
$datetimeField,
IntlDateFormatter::LONG,
IntlDateFormatter::LONG,
$locale
);
die("\n{$html}\n");
from laminas-form.
Hello @Slamdunk ,
should I prepare a pull-request for this?
kind regards
PS
We can use a simple sprintf
or , since we already have a DateTimeInterface
instance, just use the non-localized formatter:
Example for days select-option
protected function getDaysOptions($pattern, string $locale, int $dateType): array
{
$dateFormatter = new IntlDateFormatter($locale, $dateType, IntlDateFormatter::NONE, null, null, $pattern);
$date = new DateTime('1970-01-01');
$result = [];
for ($day = 1; $day <= 31; $day++) {
$key = sprintf('%02d', $day); // 1
$key = $date->format('d'); // 2
$value = $dateFormatter->format($date->getTimestamp());
$result[$key] = $value;
$date->modify('+1 day');
}
return $result;
}
from laminas-form.
Related Issues (20)
- After update from 2.17 to 3.1.1: Nested fieldset results in TypeError: template is undefined HOT 3
- Problems in tests with collections and setValidationGroup() HOT 3
- FormAttributeBuilder exception break on php 7.4 HOT 9
- Github pages isn't working( HOT 7
- Dependency Dashboard
- Add onfocusout on $validGlobalAttributes HOT 1
- ComposedObject annotation doesn't work with Required(false)
- Can't require latest package version when using PHP 8.0 running composer HOT 4
- Ability to wrap element for complex form rendering HOT 4
- Bug of day 31 (Element\Month) HOT 4
- DateTime related elements should accept DateTimeInterface values HOT 1
- Date pattern parsing fails with "exotic" locales HOT 6
- Date/Time selects helpers __invoke args may have no effect
- IntlDateFormatter::SHORT is not handled correctly by date-time select helper HOT 1
- [RFC] Improve type inference for `getData()` HOT 3
- \Laminas\Form\View\Helper\FormSelect does not allow class attribute for <option>s HOT 2
- FormMultiCheckbox doesn't render zero as hidden element HOT 2
- Problem with different Renderer HOT 6
- DateTimeLocal considers the "step" attribute to be minutes, when the HTML element specification asserts that it is seconds HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laminas-form.