I have a Textbox that is for a date field. in this Textbox i have the mask: ####-##-## ##:## and this can be defined as “YYYY-MM-DD HH:MM” so my issue is that if i go into the textbox when it contains no text i can enter all numbers and it will automatically populate the '-'s and the ':'s no problem. my issue is if i go into a textbox that has text already in it and try to change the text, then it will allow me to delete as many characters as i want, but if i delete more than 1 character i cannot input anything Whereas if i only delete one character i can add one character in its place.
I have in the textbox: 2016-03-10 12:00 and i want to change the date to the 25th. i have to
- delete the 1 from -10 then add a 2.
- delete the 0 from -10 then add a 5.
If i dont delete one character and add one character at a time then the textbox will not allow me to make any changes to the contents.
I have 2016-03-10 12:00 in the textbox and i delete 2016 from the contents to add 3567 (just an extreme example). If i remove all 4 characters then what is left is -03-10 12:00 so now if i try and add 3567 it wont let me add anything. nothing at all.
Anyone have any suggestions of why the mask is restricting me from editing already populated listboxes?
Why not use a format instead ?
Because the Text needs to be in the format that the mask is allowing and i cant have any user input error by not following the format set by the mask. is there a way i can mimic the mask but with format?
Maybe you would have a more ergonomic UI using several TextField, instead of such a complex mask.
A lot of interfaces today, especially on the web, would use several fields : one for year, another one for month, another one for day, and another one for time. With the proper code, you can have the cursor jump automatically from one box to the other when it is complete. Users are accustomed to that.
Another approach would be to employ a UI Date/Time picker, such as Mike Cotrone’s https://github.com/mikecotrone/CalendarTimeChooser.git
I do have a Date picker that automatically assigns the time of Midnight but that is where i first noticed the issue that when the user tried to change the time they can only change it one character at a time.
If you use several textfields you will not have this issue. I just tried what I described, it lets you do any kind of modification.
You can validate the value in the TextChanged event and alert the user of errors when the format is wrong.
The least obtrusive method would be to color the text red.
[quote=252536:@Tim Parnell]You can validate the value in the TextChanged event and alert the user of errors when the format is wrong.
The least obtrusive method would be to color the text red.[/quote]
I would do it in the lost focus or when user pressed [TAB], [ENTER] or [RETURN] instead. TextChanged will fire for each character, and might not give the user time to finish entering the data before an exception was raised.
somewhere I have a subclass that can be set to Text, Date, SSN, Telephone, Integer, or Float numbers and you can’t leave until it meets the type and format
I would argue that forcing the user to stay in the field until it meets a format is a poor way to handle it. Imagine not knowing why you can’t leave a field. That’s why I suggested an every character unobtrusive validation. Red text gets the point across without locking the user into a field.
You would of course want to make sure it’s valid before allowing the data to be submit or used, but treating users like they’re stupid (even if they are) is a good way to piss them off. Notifying with a message box when submitting is acceptable, as they only see it once.
Sorry… just because I didn’t provide a fully documented use-case for my subclass does not mean its stupid, or pisses people off. As a matter of fact it contains complete feedback to user as to why, and DOES allow them to move on if they so desire, but NOT to commit the data. 1st Attempt to leave the field in an error condition returns them to the same field with an explanation, 2nd attempt to leave is accepted even if field is still in error… But commit is denied if any or all fields are in error condition at that time.