I need to have a start and end time widget on a form.
i.e. the user selects a date and then selects the start and end time.
In the standard date widget, you can select a date and a time, however I need to be able to select a finish time too.
Have any of you done it before?
I could create 3 separate widgets:
- Date
- Start Time
- End Time
When the form is saved, I’ll do an update on the object to combine all values into one. For example, I’ll get the date and add the start time to it and then save to the field “start_date” and then I’ll get the date and add the end time to it and then save to the field “end_date”. It does however seem a very long winded way to do something which should be fairly trivial for a form framework.
Is this how you’d do it? Thanks guys!
I think what you want to want achieve with symfony forms is pretty easy. You are right, you need three separate widgets and three separate validators, there isn’t an out of the box solution for this exact situation.
In your form configure method you would have something like:
Let’s assume that the object has two properties, as you suggested, both are datetime fields.
In your action you would have something like the following to set the datetime fields:
Edit: another suggestion is not use the built in time widget sfWidgetFormTime as it can look pretty ugly. You can simply use a normal text box (centre aligned, with maxlength=5), and the sfValidatorTime validator will still work perfectly.
Hope that helps.