-
Notifications
You must be signed in to change notification settings - Fork 273
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
[SF][DataPicker] - DataPicker's internal validation reset valueState unexpectedly #3516
Comments
Hi @2bno1 Can you please update your isolated sample because it currently has a couple of errors and I am not sure what exact interaction are you trying to achieve Currently if you try to interact with the sample you will see that there is a JS error thrown. Once you fix it, the |
Not OP, but I think I can clear things up. The problem is that the DatePicker Component changes its own value state implicitly if it's in an Error State and a new date value is being set. This behavior is incorrect, because the Datepicker component knows absolutely nothing about the validation/business logic of the consumer. For example assume I have a validation rule that only fridays are acceptable inputs, and that a value is required. On initialization I set the value state prop to Error, because a value is required. As the user selects a date, The Datepicker component internally checks if the given date is a js Date object DatePicker.js#L505 If this check passes and the value state is "Error", the component changes the value state to 'None'. This is incorrect. My validation logic is not that trivial, and the component should not make that decision for me. If I set the value state to 'Error' it should stay that way until my validation logic determines that the user selected value is valid (in this silly example, that the date is a friday). It works correctly for value states: 'None', 'Information' and 'Warning' (the component does not set the value state to None when the date value is changed), but is wrong in the 'Error' case. You cannot handle validation for me since you cannot know my requirements. If I use Vue and bind the value state prop to a computed method, with my custom validation rule (only accept fridays as input), this implicit internal validation ignores my validation logic and simply overwrites the value state prop, making the component unusable. hope this helps. |
@phipsalabim Thanks, this is exactly what I mean. The value state should be determined by the consumer of DatePicker component instead of DatePicker itself. @fifoosid I hope it's clear now. |
You can achieve this behaviour quite easily with our current API's I have prepared example for your use case. All you need to do is to set the Note: In the provided example, it might not work for each timezone correctly (based on your location it might work for Thursday instead of Friday) PS: I just noticed that the sample might not work as expected initially because of some errors related to codeSandbox. If so, just refresh the inner browser page(the one with the datepicker) |
You are still missing the point. I probably explained myself poorly. The problem is that you are overriding the value-state prop of the datepicker internally. This makes Databinding impossible. Nobody can bind any data to the datepicker's value-state prop if the datepicker changes that prop on its own, when a date is selected. Yes I know that I can get a dom ref to the datepicker and manually set the value state to 'Whatever', but at this point I'm back in 2004 writing jquery applications. People want to bind their pure data models to props on ui components. And those ui components had better not mutate those props on their own, otherwise we can all forget about databinding. The same issue has now been reported by another user: issue #3571 |
As you already mentioned, this issue is duplicate of #3571 After an internal discussion, I am reopening this issue and it will be worked on |
FYI @SAP/ui5-webcomponents-topic-b |
In this change we introduce the preventable behaviour of the change event in the DatePicker control. This change will allow the application developers to control the whole value setting and value validation, this means that they will receive this event before we set the value and the value state and will have the possibility to prevent our setters and validators and update the value and the value state themselves. Fixes: #3516 Closes: #3516
In this change we introduce the preventable behaviour of the change event in the DatePicker control. This change will allow the application developers to control the whole value setting and value validation, this means that they will receive this event before we set the value and the value state and will have the possibility to prevent our setters and validators and update the value and the value state themselves. Fixes: #3516 Closes: #3516
Hello @2bno1 With this change you can prevent the default behaviour of the DatePicker on "change" and "input" events and it's up to you to set the both the The event details will provide both the selected "value" and the "valid" as params and you can use them to set the value and the valueState as shown bellow: datePicker.addEventListener('change', function(e) {
// Prevent setting value and valueState
e.preventDefault();
// Check the available event details
e.detail.value // Returns the value typed or selected by the user
e.detail.valid = // Indicates if the value is valid or not ("true" or "false"), based on the format, min-date and max-date props, etc.
// Set the value and the valueState
datePicker.value = e.detail.value;
datePicker.valueState = // "Error or None", based on internal logic or based on the e.detail.valid event parameter
}); Let me or @tsanislavgatev know if you have questions how to use this enhancement. |
Hello @2bno1 yes we tested it and we could reproduce the issue, as now the event is preventable, the event is first fired and then the state is updated, that's why the dateValue getter points to the old value. We will fix that probably in a day or two period of time. Sorry for the inconvenience. |
Hello @2bno1 the "dateValue" getter should be fixed in 0.31.16. |
Bug Description
The DatePicker component has built-in validation (https://github.com/SAP/ui5-webcomponents/blob/master/packages/main/src/DatePicker.js#L502). Each time the value is changed, the built-in validation is done and if it pass and original
valueState
isError
, it changes thevalueState
toNone
.For some reason, we have some complex validation logic that is triggered when the value is changed and we don't set
minDate
andmaxDate
.valueState
andvalueStateMessage
are set based on the validation result.Expected Behavior
valueState
is only determined by the caller of DatePicker and should not be changed internallySteps to Reproduce
Error
but it's changed toNone
Isolated Example
https://codesandbox.io/s/ui5-webcomponents-forked-4bndy?file=/index.html
Context
Priority
Stakeholder Info (if applicable)
The text was updated successfully, but these errors were encountered: