try and deal with widget value nonsense

This commit is contained in:
Sanj 2012-07-20 03:03:40 +05:30
parent e766fdc858
commit 16e296d9f4
3 changed files with 5 additions and 2 deletions

View File

@ -39,7 +39,9 @@ class AutocompleteAddWidget(forms.Select):
if choice[0] == id:
return choice[1]
return ''
#import pdb
#pdb.set_trace()
ctx = super(AutocompleteAddWidget, self).get_context(name, value, attrs)
if value:
ctx['title'] = get_matched_choice_title(self.choices, value)

View File

@ -1,2 +1,2 @@
<input type="hidden" id="id_{{name}}" name="{{name}}" data-ctype="{{ ctype.id }}" class="select2class" data-id="{% if value %}{{ value }} {% endif %}" data-title="{% if title %} {{ title }} {% endif %}" style="width:600px;" /> <a href="/popup_form/{{ ctype.id }}" class="popup_add_btn" title="Add new" id="add_{{name}}" onclick="return showAddAnotherPopup(this);">+</a>
<input type="hidden" id="id_{{name}}" name="{{name}}" data-ctype="{{ ctype.id }}" class="select2class" data-id="{% if value %}{% for v in value %}{{v}}{% endfor %}{% endif %}" data-title="{% if title %}{{ title }}{% endif %}" style="width:600px;" value="" /> <a href="/popup_form/{{ ctype.id }}" class="popup_add_btn" title="Add new" id="add_{{name}}" onclick="return showAddAnotherPopup(this);">+</a>

View File

@ -77,6 +77,7 @@ $(function(){
}
});
var id = $this.attr("data-id");
console.log(id);
if ($.trim(id) !== '') {
var title = $this.attr("data-title");
$this.select2("val", {'id': id, 'title': title});