Setting default time for time picker
Setting default time for time picker
Another one for the mighty Allan I think.
Is there an easy way to set a default time when the time picker widget displays or initially sets the time in an input field?
At the moment it defaults to the current hour and '-' for minutes (I've got 15 min increments set). When the on chnage event is fired by a user changing the hour, the input field updates to show the selected hour and the current minute. If the current time is 09:33 and I click the timedate field and change the hour select to 10 the input field will display 10:33. I'd like my users to only be able to select either 00,15,30,45, is there a way to default the mins to 00 when the widget is displayed/input field is initially updated?
Also, is it possible to make editor fields read only so users have to use the date/time picker rather than being able to manually enter dates and times?
Cheers
This question has an accepted answers - jump to answer
Answers
The
field.def
option should do that:You could bind a
keydown
event listener to the input element (field().input()
) and simply usee.preventDefault()
to stop their key press from having any effect. That would remove copy and paste support as well, unless you add logic to allow them.Allan
Ooops - sorry I missed this bit:
You'd need to add that rounding option into the
def
function. Take the current time and round it to be 0, 15, 30 or 45. Editor's date time picker won't do that rounding for you I'm afraid.I'm in two minds as it if it should or not! I can see that it might be useful without question, but at the same time, if you feed it "33" for example and it rounds to "30", rather might be considered to corrupt the data...
Allan
Brilliant, thank you again for all your help Allan.
Allan,
I note that this def: option works fine when creating a new record.
But I am seeing that def: does not work when editing an existing record. i.e. I have an existing record with a blank datetime field. I wish to have the datetime picker default to a rounded 00,15,30,45 minute when editing that blank field for the first time.
In the editor, how can one set that default rounded date/time in the spawned datetime calendar without populating the field first?
I am trying to do this within
But it is already pre-populating the field but I do not want that yet until the calendar datetime is set.
BTW this is what I use for rounding
The default is more or less ignored when editing (rather than creating) since the field already has a value - even if that value is empty. Replacing an existing value with the default would be wrong, which is why it isn't going to work using the default value.
What I would suggest is that you use
initEdit
to check the values and replace / update them if needed on triggering editing.Allan