# HG changeset patch # User Sylvain Thénault # Date 1342519612 -7200 # Node ID 05992aa3fc0d802f4c4474979e882b1b82d721d8 # Parent a85e107947e63986bd42cb625b56cd4ac75d6ff9 [form widgets] fix JQueryDatePicker and JQueryTimePicker so they consider widget custom attributes. Closes #2423720 diff -r a85e107947e6 -r 05992aa3fc0d web/formwidgets.py --- a/web/formwidgets.py Wed Jul 18 15:58:20 2012 +0200 +++ b/web/formwidgets.py Tue Jul 17 12:06:52 2012 +0200 @@ -672,10 +672,11 @@ """ needs_js = ('jquery.ui.js', ) needs_css = ('jquery.ui.css',) + default_size = 10 def __init__(self, datestr=None, **kwargs): super(JQueryDatePicker, self).__init__(**kwargs) - self.datestr = datestr + self.value = datestr def _render(self, form, field, renderer): req = form._cw @@ -689,44 +690,36 @@ '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,' ' showOn: "button", buttonImageOnly: true})' % ( domid, req.uiprops['CALENDAR_ICON'], fmt)) - if self.datestr is None: + return self._render_input(form, field, domid) + + def _render_input(self, form, field, domid): + if self.value is None: value = self.values(form, field)[0] else: - value = self.datestr - attrs = {} - if self.settabindex: - attrs['tabindex'] = req.next_tabindex() - return tags.input(id=domid, name=domid, value=value, - type='text', size='10', **attrs) + value = self.value + attrs = self.attributes(form, field) + attrs.setdefault('size', unicode(self.default_size)) + return tags.input(name=domid, value=value, type='text', **attrs) -class JQueryTimePicker(FieldWidget): +class JQueryTimePicker(JQueryDatePicker): """Use jquery.timePicker to define a time picker. Will return the time as an unicode string. """ needs_js = ('jquery.timePicker.js',) needs_css = ('jquery.timepicker.css',) + default_size = 5 def __init__(self, timestr=None, timesteps=30, separator=u':', **kwargs): - super(JQueryTimePicker, self).__init__(**kwargs) - self.timestr = timestr + super(JQueryTimePicker, self).__init__(timestr, **kwargs) self.timesteps = timesteps self.separator = separator def _render(self, form, field, renderer): - req = form._cw domid = field.dom_id(form, self.suffix) - req.add_onload(u'cw.jqNode("%s").timePicker({selectedTime: "%s", step: %s, separator: "%s"})' % ( - domid, self.timestr, self.timesteps, self.separator)) - if self.timestr is None: - value = self.values(form, field)[0] - else: - value = self.timestr - attrs = {} - if self.settabindex: - attrs['tabindex'] = req.next_tabindex() - return tags.input(id=domid, name=domid, value=value, - type='text', size='5') + form._cw.add_onload(u'cw.jqNode("%s").timePicker({step: %s, separator: "%s"})' % ( + domid, self.timesteps, self.separator)) + return self._render_input(form, field, domid) class JQueryDateTimePicker(FieldWidget):