symfony1 - Symfony Forms Start and End Time Widget -
i need have start , end time widget on form.
i.e. user selects date , selects start , end time.
in standard date widget, can select date , time, need able select finish time too.
have of done before?
i create 3 separate widgets:
- date
- start time
- end time
when form saved, i'll update on object combine values one. example, i'll date , add start time , save field "start_date" , i'll date , add end time , save field "end_date". seem long winded way should trivial form framework.
is how you'd it? guys!
i think want want achieve symfony forms pretty easy. right, need 3 separate widgets , 3 separate validators, there isn't out of box solution exact situation.
in form configure method have like:
$this->setwidgets(array( 'date' => new sfwidgetformdate(), 'time_start' => new sfwidgetformtime(array('label' => 'start time', 'with_seconds' => false)), 'time_finish' => new sfwidgetformtime(array('label' => 'end time', 'with_seconds' => false) )); $this->setvalidators(array( 'date' => new sfvalidatordate(), // default outputs in format y-m-d 'time_start' => new sfvalidatortime(), // default outputs in format h:i:s 'time_finish' => new sfvalidatortime(), ));
let's assume object has 2 properties, suggested, both datetime fields.
in action have following set datetime fields:
$values = $this->form->getvalues(); $object->setstartdatetime(sprintf('%s %s', $values['date'], $values['time_start'])); $object->setfinishdatetime(sprintf('%s %s', $values['date'], $value['time_finish']));
edit: suggestion not use built in time widget sfwidgetformtime can pretty ugly. can use normal text box (centre aligned, maxlength=5), , sfvalidatortime validator still work perfectly.
hope helps.
Comments
Post a Comment