python - Django SelectTimeWidget readonly -


here django code,

class fpool_booked(forms.form):      = forms.charfield(label = 'departure place',max_length = 30,widget=forms.textinput(attrs={'readonly':'readonly'}),error_messages = {'required': 'please enter want go'})      = forms.charfield(label = 'destination place',max_length = 30,widget=forms.textinput(attrs={'readonly':'readonly'}),error_messages = {'required': 'please enter destination'})      from_time = forms.timefield(label = 'departure time',widget = selecttimewidget(attrs={'readonly':'readonly'},twelve_hr = true)) 

as can see have made text field readly works fine ,in same way wanna make selecttimewidget readonly have tried attrs={'readonly':'readonly'} not work expected. there way fix ?/

the selecttimewidget custom widget based on selectdatewidget. don't think supports 'readonly'. i've overdone answer had play , came following may if want it...

i dropped selecttimewidget snippet code , changed following lines

def __init__(self, attrs=none, hour_step=none, minute_step=none, second_step=none, twelve_hr=false): 

to:

def __init__(self, attrs={'readonly':'readonly'}, hour_step=none, minute_step=none, second_step=none, twelve_hr=false): 

and:

select_html = select(choices=hour_choices).render(self.hour_field % name, hour_val, local_attrs) select_html = select(choices=minute_choices).render(self.minute_field % name, minute_val, local_attrs) select_html = select(choices=second_choices).render(self.second_field % name, second_val, local_attrs) 

to:

select_html = textinput().render(self.hour_field % name, hour_val, local_attrs) select_html = textinput().render(self.minute_field % name, minute_val, local_attrs) select_html = textinput().render(self.second_field % name, second_val, local_attrs) 

i used following form style when want post values form fields , more dynamic, able access values within form , change form on fly.

class time_form(forms.form):     def __init__(self, *args, **kwargs):         super(time_form, self).__init__(*args, **kwargs)          self.fields['from'] = forms.charfield(widget=forms.textinput(attrs={'onchange':'this.form.submit()'}))         self.fields['to'] = forms.charfield(widget=forms.textinput(attrs={'onchange':'this.form.submit()'}))         self.fields['from_time'] = forms.timefield(widget = selecttimewidget()) 

in view set values see how looked:

form = time_form({'from_time':'12:34:56 p.m.',}) 

note left in attrs={'onchange':'this.form.submit()'} fun of in case want dynamically update form when changes made, (and show attr= goes), although find tends work best select widgets. in form can access 'from' , 'to' values (e.g. var = args[0].get('to')) , update 'from_time' (args[0]['from_time']= function).

secondly, 'from_time' widget glorified read textinput box parses time formats seems complicated way go.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -