Friday, 15 April 2011

python - Make text box visible based on the item selected in dropdown django, forms -



python - Make text box visible based on the item selected in dropdown django, forms -

my forms.html

<fieldset class="task-info"> {{ form_field(task_form['execution_time']) }} {{ form_field(task_form['admin_time']) }} {{ form_field(task_form['difficulty']) }} {{ form_field(task_form['priority']) }} </fieldset>

my form.py

class taskform(forms.modelform): admin_time = forms.charfield( help_text=_('enter if more 60 minutes.'), required=false, widget=forms.textinput(attrs={'class': 'fill-width'})) keywords = (forms.charfield( help_text=_('please utilize commas separate keywords.'), required=false, widget=forms.textinput(attrs={'class': 'medium-field'}))) def __init__(self, *args, **kwargs): if kwargs['instance']: initial = kwargs.get('initial', {}) initial['keywords'] = kwargs['instance'].keywords_list kwargs['initial'] = initial super(taskform, self).__init__(*args, **kwargs) def _process_keywords(self, creator): if 'keywords' in self.changed_data: kw = [k.strip() k in self.cleaned_data['keywords'].split(',')] self.instance.replace_keywords(kw, creator) def clean(self): cleaned_data = super(taskform, self).clean() start_date = cleaned_data.get('start_date') end_date = cleaned_data.get('end_date') if start_date , end_date: if start_date >= end_date: raise forms.validationerror(_("'end date' must after 'start date'")) homecoming cleaned_data def save(self, creator, *args, **kwargs): self.instance.creator = creator super(taskform, self).save(*args, **kwargs) if kwargs.get('commit', true): self._process_keywords(creator) homecoming self.instance class media: css = { 'all': ('css/admin_ace.css',) } class meta: model = task fields = ('name', 'short_description', 'execution_time', 'difficulty', 'priority', 'repeatable', 'team', 'project', 'type', 'start_date', 'end_date', 'why_this_matters', 'prerequisites', 'instructions', 'is_draft', 'is_invalid') widgets = { 'name': forms.textinput(attrs={'size': 100, 'class': 'fill-width'}), 'short_description': forms.textinput(attrs={'size': 100, 'class': 'fill-width'}), 'instructions': acewidget(mode='markdown', theme='textmate', width='800px', height='300px', wordwrap=true, attrs={'class': 'fill-width'}), 'start_date': calendarinput, 'end_date': calendarinput, 'why_this_matters': forms.textarea(attrs={'rows': 2, 'class': 'fill-width'}), 'prerequisites': forms.textarea(attrs={'rows': 4, 'class': 'fill-width'}), }

models.py there's class class task(cachedmodel, createdmodifiedmodel, createdbymodel): in execution_time defined

execution_time = models.integerfield( choices=((i, i) in (15, 30, 45, 60)), blank=false, default=30, verbose_name='estimated time' )

what want accomplish there should 1 more selection after 60, can 'add new value',when alternative taken admin_time textbox should appear.

any 1 on how accomplish ? need utilize javascript assume

put input box in div.

.text-box-div { display:none; }

add jquery

$(document).ready(function(){ $('.text-box-div').hide(); $('.add-new-value').show(); $('.add-new-value').click(function(){ $('.text-box-div').slidetoggle(); }); });

python django forms

No comments:

Post a Comment