[MGNLUI-4271] DateField: default value can not be set -> yaml parses the Date (and Time) String automatically Created: 18/Aug/17 Updated: 13/Sep/17 Resolved: 13/Sep/17 |
|
| Status: | Closed |
| Project: | Magnolia UI |
| Component/s: | forms |
| Affects Version/s: | 5.5.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Neutral |
| Reporter: | Christian Ringele | Assignee: | Unassigned |
| Resolution: | Not an issue | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Template: |
|
||||||||
| Acceptance criteria: |
Empty
|
||||||||
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||||||
| Bug DoR: |
[ ]*
Steps to reproduce, expected, and actual results filled
[ ]*
Affected version filled
|
||||||||
| Date of First Response: | |||||||||
| Description |
|
Configuring on a DateFieldDefintion a default value like this defaultValue: 2015-01-01 throws an exception: Caused by: java.text.ParseException: Unparseable date: "Thu Jan 01 01:00:00 CET 2015" at java.text.DateFormat.parse(DateFormat.java:366) at info.magnolia.ui.vaadin.integration.jcr.DefaultPropertyUtil.createTypedValue(DefaultPropertyUtil.java:164) ... 137 more The reason: Regarding Time: |
| Comments |
| Comment by Antti Hietala [ 13/Sep/17 ] |
|
Default value can be set but you must enclose it in quotes when using YAML:
defaultValue: "2017-10-31"
If you define the dateFormat or timeFormat properties then provide the defaultValue using those same formats.
dateFormat: yyyy-MM-dd
timeFormat: h:mm a
defaultValue: "2017-10-31 3:09 PM"
The format properties are used in two ways:
Case 2 is a bit flaky but mostly it works fine. The system expects the default value to be given as dateFormat + " " + timeFormat, see DateFieldFactory (Git). This works reliably for simple formats like yyyy-MM-dd HH:mm but if you define a very exotic format such as EEE, MMM d, yyyy (Tue, Oct 31, 2017) the system will fail to parse the default value correctly. Date field documentation was updated. |
| Comment by Christian Ringele [ 13/Sep/17 ] |
|
ahietala ah man I haven't realised that it needs to be provided as a Sting... my bad. |