on 03-01-2019 3:43 AM
How can I restrict user to enter date in only dd/mm/yyyy format? I tried regular expression in datepicker but it is too complex for others if they want to make modifications. Please help me resolve this. Thanks in advance.
This answer suggests to use binding type instead (such as 'sap.ui.model.odata.type.DateTime') which restricts the input value to be stored in the model if it could not be parsed or validated.
Example:
<DatePicker placeholder="DD/MM/YYYY" value="{
path: 'myODataModel>myDate',
type: 'sap.ui.model.odata.type.DateTime',
formatOptions: {
pattern: 'dd/MM/yyyy'
},
constraints: {
isDateOnly: true,
displayFormat: 'Date'
}
}"
The value will be always displayed in the dd/MM/yyyy pattern. But the model stores the value in JS-Date object (Internally, the thirdparty lib datajs will convert it again to OData conform format before it's sent).
Finally, register the control in the message manager to activate automatic message generation as shown in the documentation topic UI Messages.
Sample JSBin: https://jsbin.com/seyutiw/edit?js,output
_____________
If the model is not an ODataModel but just a plain JSONModel:
<DatePicker placeholder="DD/MM/YYYY" value="{
path: 'myJSONModel>myDate',
type: 'sap.ui.model.type.Date',
formatOptions: {
pattern: 'dd/MM/yyyy'
}
}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
screenshot-from-2019-03-07-09-29-26.png
screenshot-from-2019-03-07-09-30-18.png
I'm getting these errors.
pavankumaran#overview
The error message you were getting was due to the missing comma which I fixed in the above answer. I also added another snippet in case the "Project" model is a JSONModel instead of OData. You can check the JSBin sample I added to the answer.
Please try again and let us know if this solution was helpful.
Hi Pavankumar A N,
Use the given Properties in Date Picker
valueFormat
and displayFormat
< DatePicker valueFormat="dd.MM.yyyy" >
BR
Arun Mathew
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.