ui5-date-picker removes error value state by itself
Bug Description
We are using a ui5-date-picker in with an error value state. When the selected date is changed to another invalid date, we want to keep the Error state. As the Date Picker is removing the error state by itself, we can't achieve this because React still thinks that the value-state is Error and not None
Expected Behavior
value-state should be fully controllable by end users
Steps to Reproduce
- Open https://codesandbox.io/s/naughty-visvesvaraya-63pd1?file=/src/App.js
- Select a Date
- Click
Set Error Value State - Select another Date
- Click
Set Error Value Stateagain - See: no error state but state "None"
Isolated Example
https://codesandbox.io/s/naughty-visvesvaraya-63pd1?file=/src/App.js
Context
- UI5 Web Components version: 1.0.0-rc.14 (happens with rc.15 candidate as well)
- Affected component:
ui5-date-picker, maybe other inputs as well?
Priority
- [ ] Low
- [x] Medium
- [ ] High
- [ ] Very High
Hello @SAP/ui5-webcomponents-topic-b could you look at the issue, it is described fine and reproducible with the steps above.
Hello @MarcusNotheis,
Тhis is the expected behaviour of the control, because it gives an option for a manual valueState change, but it also keeps the default validation. For example if you exclude the validation of the control, you can type something like '31233d1s2a3'( invalid date) and it won't take any action, and this won't be correct from component side. But there is an option, for example an event listener on 'change' event on the component should work for every change. I've forked the provided snippet into a one that gives the application developer control over the state based on a simple option. https://codesandbox.io/s/dazzling-chaum-cr9pl?file=/src/index.js
Best Regards, Tsanislav
@tsanislavgatev In the example https://codesandbox.io/s/dazzling-chaum-cr9pl?file=/src/index.js, the manual value state change (triggered by clicking Change Value State to Error) only takes effect at the first time. You can reproduce this by:
- Click 'Change Value State to Error' button (Value State is set to Error)
- Pick a date from date picker (Value State is set to None)
- Click 'Change Value State to Error' button again (Value State is still None)
The reason is
- When the button is clicked the first time,
isErroris changed fromfalsetotrue,Appis re-rendered,ui5-date-pickeris re-rendered withErrorvalue state. - Picking a date from date picker, the ui5-date-picker set the value state to
Noneinternally. https://github.com/SAP/ui5-webcomponents/blob/master/packages/main/src/DatePicker.js#L506 - However, when the button is clicked the second time (or later),
isErroris kepttrue,Appwill not be re-rendered, so the value state ofui5-date-pickeris keptNone.
I've also submitted a similar issue #3516
You can also compare the behaviour to the SAPUI5 Date Picker. The value state does not change automatically, no matter what you do with the DatePicker.
Hi @tsanislavgatev
Тhis is the expected behaviour of the control
If that's the case, then the expected behaviour should be revised. As it currently stands, this behaviour makes it impossible to use databinding with the value-state prop, and ultimately makes this component unusable/extremely painful for react/angular/vue/svelte users. State can not be bound to the value-state prop if the component overwrites the value of that prop
The Datepicker provides a prop value-state, yet completely ignores what the user passed into it if a date is selected. That cannot possibly be desirable. It's equivalent to a function that ignores a parameter that was passed into it, and performs the computation with a different random value.
If a component internally mutates the value of a prop, it destroys any databinding to that prop, and using that component becomes infuriating and confusing.
Very few users write jquery style applications, where it is normal to proceduraly set attributes on dom refs, in a haze of event listeners and callbacks.
Most users will declaratively bind their datamodel to the relevant component props. Including the value-state prop. The value-state should be determined by the data model not by the datepicker. Please do not overwrite it. The datepicker does not know what a valid date is in my business logic. My datamodel has that information. It binds it to the datepicker, which is simply supposed to render that state, rather than ignoring/overwriting it.
As @MarcusNotheis noted, it is not the behaviour of the equivalent ui5 datepicker control
I find it concerning how casually this rather severe issue is being dismissed. twice.
HI @phipsalabim , @2bno1
As it is explained here, we had to discuss how to proceed with this issue. We decided to work on it. I have reopened the other issue and you can keep track of progress there.
Hi @fifoosid,
That's great to hear. Thanks!