Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rangeSeparator attribute to DatePicker #4818

Closed
morvael opened this issue May 17, 2019 · 9 comments

Comments

Projects
None yet
6 participants
@morvael
Copy link

commented May 17, 2019

With pattern set to "yyyy-MM-dd" it's impossible to use selectionMode "range". DatePickerRenderer has hardcoded separator string in line 186, and since the number of elements in the parts array isn't equal to 2, it doesn't even try to parse those dates. Please allow to specify different separator string for range and multiple selectionModes.

1) Environment

  • PrimeFaces version: 7.0.2
  • Application server + version: WildFly 16.0.0
  • Affected browsers: All

2) Expected behavior

Getting list with two elements.

3) Actual behavior

Getting empty list.

@melloware

This comment has been minimized.

Copy link
Contributor

commented May 18, 2019

Good debugging. I think you mean this line 194:
https://github.com/primefaces/primefaces/blob/master/src/main/java/org/primefaces/component/datepicker/DatePickerRenderer.java#L193-L200

            case "range": {
                String[] parts = submittedValue.split("-");
                List<Object> range = new ArrayList<>();
                if (parts.length == 2) {
                    for (String part : parts) {
                        range.add(super.getConvertedValue(context, component, part));
                    }
                }
@morvael

This comment has been minimized.

Copy link
Author

commented May 18, 2019

In my sources for 7.0.2 (we have commercial support, and probably there is different license header) the line number is different, but it's the same piece of code.

@morvael

This comment has been minimized.

Copy link
Author

commented May 18, 2019

By the way I wanted to write my own coverter to custom object (range with two fields "from" and "to"), and with the way this code is written it's impossible to do it.

@youngroman

This comment has been minimized.

Copy link

commented May 24, 2019

same issue here. easy fix would be to change the default separators to include the spaces. I don't know of a Date/Time-Pattern that uses ", " or " - " so this might be a permanent fix unless you decide to customize the separators.

proposed code looks like this:
case "multiple": { String[] parts = submittedValue.split(", ");
and
case "range": { String[] parts = submittedValue.split(" - ");

@melloware

This comment has been minimized.

Copy link
Contributor

commented May 24, 2019

@youngroman not a bad suggestion. @mertsincan WDYT? I can submit a PR if you think its OK.

melloware added a commit to melloware/primefaces that referenced this issue May 24, 2019

@tandraschko tandraschko added the defect label Jun 28, 2019

@Edubits

This comment has been minimized.

Copy link

commented Jul 4, 2019

Please note the same issue exists in PF 7.0.4 in datepicker.js. text.split(/-| - /) is used instead of text.split(' - ')

melloware added a commit to melloware/primefaces that referenced this issue Jul 5, 2019

@melloware

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

@mertsincan the JS piece @Edubits is talking about above is in the shared DatePicker code between PrimeNG, PrimeReact, and PrimeFaces so I am hesitant to touch it. Can you please review?

@mertsincan

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

Hi @melloware,

We can add "rangeSeparator" attribute for this issue.

@mertsincan mertsincan changed the title DatePicker: range not working with - as date part separator Add rangeSeparator attribute to DatePicker Jul 5, 2019

@mertsincan mertsincan added this to the 7.1 milestone Jul 5, 2019

@mertsincan mertsincan closed this in 394ad8e Jul 5, 2019

@mertsincan

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

Hi @morvael

Please use rangeSeparator attribute.

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.