Skip to content

Commit

Permalink
Fix ControlAutoComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Feb 13, 2019
1 parent c5f3d99 commit c032171
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pyforms_web/web/static/pyforms.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions pyforms_web/web/static/pyformsjs/ControlAutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ class ControlAutoComplete extends ControlBase{
html += '<div class="default text">'+this.properties.label+'</div>';
html += '</div>';
this.jquery_place().replaceWith(html);

// get the items from an url
this.jquery().dropdown({
apiSettings: { url: this.properties.items_url },
apiSettings: { url: this.properties.items_url, cache:false },
saveRemoteData: false,
placeholder: false,
forceSelection: false
});

this.jquery().dropdown('setup menu', { values: this.properties.items });
this.set_value(this.properties.value);



var self = this;
this.jquery().dropdown('setting', 'onChange', function(){
if(self.flag_exec_on_change_event)
self.basewidget.fire_event( self.name, 'update_control_event' );
});

if(this.properties.error) this.jquery_place().addClass('error'); else this.jquery_place().removeClass('error');
};

Expand Down Expand Up @@ -58,11 +57,10 @@ class ControlAutoComplete extends ControlBase{

deserialize(data){
this.properties = $.extend(this.properties, data);

this.jquery().dropdown('setup menu', { values: this.properties.items });
this.set_value(this.properties.value);


if(this.properties.error) this.jquery_place().addClass('error'); else this.jquery_place().removeClass('error');
};

Expand Down
13 changes: 6 additions & 7 deletions pyforms_web/widgets/django/modelform.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ def create_model_formfields(self):


elif isinstance(field, models.Field) and field.choices:
pyforms_field = ControlCombo(
label,
pyforms_field = ControlCombo(
label,
items=[ (c[1],c[0]) for c in field.choices],
default=field.default
)
Expand All @@ -996,20 +996,19 @@ def create_model_formfields(self):
query = field.related_model.objects.all()
limit_choices = field.get_limit_choices_to()
if limit_choices: query = query.filter(**limit_choices)
pyforms_field = ControlAutoComplete(

pyforms_field = ControlAutoComplete(
label,
queryset=query,
queryset_filter=self.autocomplete_search,
default=field.default
)

elif isinstance(field, models.ManyToManyField):
query = field.related_model.objects.all()
limit_choices = field.get_limit_choices_to()
if limit_choices: query = query.filter(**limit_choices)
pyforms_field = ControlAutoComplete(

pyforms_field = ControlAutoComplete(
label,
queryset=query,
multiple=True,
Expand Down

0 comments on commit c032171

Please sign in to comment.