I have a DateObject
and InputField
that I am using to collect an inputted date. Mouseover
works well to switch between the two items. However, if the cursor is in the InputField
and the mouse drifts out of it then it switches back to the DateObject
.
reportDate = Today;
Mouseover[
Dynamic[With[{date = Interpreter["Date"][reportDateInput]},
If[DateObjectQ@date, reportDate = date, reportDate]],
TrackedSymbols :> {reportDateInput}]
,
InputField[
Dynamic[reportDateInput,
{
None,
With[{date = Interpreter["Date"][#]},
If[DateObjectQ@date, reportDateInput = #,
reportDateInput = "Try again. Date not recognised."]] &
}],
String,
FieldHint -> "Enter the report date."
]
]
How do I keep the InputField
visible as long as it has focus (e.g. text cursor in it)? Should I be using some other combination of controls? I'm only interested in the reportDate
variable. The other is just a means to that end. Also, I would like not to have to use Interpreter
twice.
This combination is to easily get a date from as there is no built in date picker at the moment. I know there are some custom date pickers out there (e.g. 16542) but I'd rather use this simpler method of free-text input at the moment. Also, I'd like to know how to do this for other UI elements.