Skip to content

Commit

Permalink
Merge pull request #76 from rodfersou/rodfersou-orderedfield-fix
Browse files Browse the repository at this point in the history
Deal with items with same name but different values in ordered field widget
  • Loading branch information
rodfersou committed Oct 3, 2018
2 parents 84b9067 + 92ce528 commit 4524492
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
4.1 (unreleased)
----------------

- Deal with items with same name but different values in ordered field widget.
[rodfersou]

- Move homegrown Manager implementation to OrderedDict
[tomgross]

Expand Down
4 changes: 2 additions & 2 deletions src/z3c/form/browser/orderedselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def deselect(self):
selecteditems = []
notselecteditems = []
for selecteditem in self.selectedItems:
selecteditems.append(selecteditem['content'])
selecteditems.append(selecteditem['value'])
for item in self.items:
if not item['content'] in selecteditems:
if item['value'] not in selecteditems:
notselecteditems.append(item)
return notselecteditems

Expand Down
11 changes: 8 additions & 3 deletions src/z3c/form/browser/orderedselect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ providing ``ITerms``. This source uses descriminators wich will fit our setup.
... self.terms = SimpleVocabulary([
... SimpleVocabulary.createTerm(1, 'a', u'A'),
... SimpleVocabulary.createTerm(2, 'b', u'B'),
... SimpleVocabulary.createTerm(3, 'c', u'C')
... SimpleVocabulary.createTerm(3, 'c', u'C'),
... SimpleVocabulary.createTerm(4, 'd', u'A'),
... ])

>>> zope.component.provideAdapter(SelectionTerms,
Expand All @@ -125,6 +126,7 @@ Now let's try if we get widget values:
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
<option value="d">A</option>
</select>
</td>

Expand All @@ -138,6 +140,7 @@ If we select item "b", then it should be selected:
size="5" multiple="multiple">
<option value="a">A</option>
<option value="c">C</option>
<option value="d">A</option>
</select>
</td>

Expand All @@ -156,10 +159,12 @@ The json data representing the oredered select widget:
'mode': 'input',
'name': 'widget.name',
'notSelected': [{'content': 'A', 'id': 'widget-id-0', 'value': 'a'},
{'content': 'C', 'id': 'widget-id-2', 'value': 'c'}],
{'content': 'C', 'id': 'widget-id-2', 'value': 'c'},
{'content': 'A', 'id': 'widget-id-3', 'value': 'd'}],
'options': [{'content': 'A', 'id': 'widget-id-0', 'value': 'a'},
{'content': 'B', 'id': 'widget-id-1', 'value': 'b'},
{'content': 'C', 'id': 'widget-id-2', 'value': 'c'}],
{'content': 'C', 'id': 'widget-id-2', 'value': 'c'},
{'content': 'A', 'id': 'widget-id-3', 'value': 'd'}],
'required': False,
'selected': [{'content': 'B', 'id': 'widget-id-0', 'value': 'b'}],
'type': 'multiSelect',
Expand Down

0 comments on commit 4524492

Please sign in to comment.