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
Closed

Add rangeSeparator attribute to DatePicker #4818

morvael opened this issue May 17, 2019 · 9 comments
Assignees
Milestone

Comments

@morvael
Copy link

morvael 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
Copy link
Member

melloware 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
Copy link
Author

morvael 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
Copy link
Author

morvael 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
Copy link

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
Copy link
Member

@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 Bug...Something isn't working label Jun 28, 2019
@Edubits
Copy link

Edubits 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
Copy link
Member

@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
Copy link
Member

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 6.2.22 7.0.5 new feature and removed 🐞 defect Bug...Something isn't working labels Jul 5, 2019
@mertsincan mertsincan added this to the 7.1 milestone Jul 5, 2019
@mertsincan
Copy link
Member

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
Projects
None yet
Development

No branches or pull requests

6 participants