I have a form that uses a SharePoint list for it's data source. I'd like to display a message to the user if they enter invalid data in the date picker. However, I don't see a way to get the information the user has entered unless the date is valid. For example, in the screenshot below, IsBlank returns true for the DataCardValue.
Is there any way to access the user-entered data in a date picker where the user-entered data is not a valid date?
You can use this as an IF condition to test if a valid date was entered
If(IsBlank(DatePicker1.SelectedDate),
true_condition_code, // this code will execute when there is an invalid date entered
false_condition_code // this code will execute when there is an valid date entered
)
---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
Right, IsBlank returns true if the user enters "aaaa" or some other invalid date. It also returns true if the user leaves the control blank.
However, if the control is blank, I don't want to display a message to the user. I would like to display a message to the user if they enter an invalid date.
Does that make sense?
@hilary_stoupa
Yes, that makes sense. I can't think of anything to solve it at the moment...
Have you considered changing the IsEditable property of the DatePicker to false? It would make users select a value using the date picker while not allowing to input "non-date entries"
If you are willing to do with out the calendar selection, you could also make a series of three text inputs or dropdowns: year, month, day. Then you could join them together for submission into the datasource like this.
Date(Value(TextInput_Year.Text), Value(TextInput_Month).Text, Value(TextInput_Day).Text)
---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
Unfortunately, users wish to be able to also type in data, since that is generally faster for them than using the date picker.
If(
!IsBlankOrError(DateValue(TextInput1.Text)),
true, // Do this when a date
false // Do this when not a date
)
You can use this evaluation to do another action like Notify, or clear the field's value. Perhaps place it on the OnChange of your input field, and then reset the value if they didn't enter a valid value.
NOTE: DateValue will check for things like 1/1, or 1/1/20, which are technically date values. If you need a specific date format, please let me know.
I'm concerned I'm being unclear. We do want to use a date picker control. We want the user to also be able to type in the date control. I'd like to be able to show an alert to the user if they type in something that is not a valid date. IsError returns false if I enter an invalid date in a date picker (like text, for example).
Does that make sense?
@hilary_stoupa
Unfortunately, there doesn't seem to be any way to do what you are asking with a datepicker. But you could use a Text Input instead and use a regular expression to validate the date format.
To test this, create a Text Input control. Then put a label beside the text box that says "date must be in the format MM/dd/yyyy".
Next put this code in the Visible property. Notice how the label changes when you haven't input a valid value.
IsMatch(TextInput2.Text,"(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d")
But you also have a requirement the warning text should not show if the user leaves the field not blank. So we must add some additional code to the Visible property.
!IsBlank(TextInput1.Text) And IsMatch(TextInput2.Text,"(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d")
Finally, if you want to output the contents of the TextInput as a date put this code in the Update property of your Edit Form or in the record argument of your Patch form.
DateValue(TextInput1.Text)
---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
Thanks, all. I think we are going to just display some warning text under the date fields and hide it if the date is not blank - that way if it is blank or invalid, the warning will show. I had just thought perhaps there was some property I was overlooking that I could use to get back the user entered value even if it was not valid.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
195 | |
69 | |
50 | |
39 | |
30 |
User | Count |
---|---|
248 | |
112 | |
95 | |
91 | |
72 |