Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Update select2 and set proper id to inital

Anna Siwik37a189662194
diff --git a/package.json b/package.json
index 35cdd58b59..3d2711d72b 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,7 @@
"query-string": "^5.0.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
- "select2": "^4.0.3",
+ "select2": "^4.0.5",
"sortablejs": "^1.5.0-rc1",
"svg-injector-2": "^2.0.35"
},
diff --git a/saleor/dashboard/forms.py b/saleor/dashboard/forms.py
index b3c7ce7e92..430bd54249 100644
--- a/saleor/dashboard/forms.py
+++ b/saleor/dashboard/forms.py
@@ -43,9 +43,11 @@ class AjaxSelect2ChoiceField(forms.ChoiceField):
forms.Field.validate(self, value)
return True
- def set_initial(self, obj, label=None):
+ def set_initial(self, obj, obj_id=None, label=None):
"""Set initially selected objects on field's widget."""
- selected = {'id': obj.pk, 'text': label if label else str(obj)}
+ selected = {
+ 'id': obj_id if obj else obj.pk,
+ 'text': label if label else str(obj)}
self.widget.attrs['data-initial'] = json.dumps(selected)
diff --git a/saleor/dashboard/menu/forms.py b/saleor/dashboard/menu/forms.py
index 5fe915ab6e..6dba2d666b 100644
--- a/saleor/dashboard/menu/forms.py
+++ b/saleor/dashboard/menu/forms.py
@@ -33,11 +33,11 @@ class MenuItemForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- destination = self.instance.destination
+ dest = self.instance.destination
- if destination:
- self.fields['linked_object'].set_initial(
- destination, self.instance.get_destination_display())
+ if dest:
+ obj_id = str(dest.pk) + '_' + dest.__class__.__name__
+ self.fields['linked_object'].set_initial(dest, obj_id=obj_id)
def save(self, commit=True):
linked_object = self.cleaned_data.get('linked_object')