From 0fb8b67fcea0dc1901e12821f045421fd9ab0125 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 25 Dec 2015 11:14:23 +0100
Subject: [PATCH] Listbox: support editing listbox where columns have been
 configured

generally speaking, listbox where some editable fields are not listed in fields
(cherry picked from commit 9abfc6c412eb8635f6ab805d0af1b5d9f3e3facd)
---
 product/ERP5Form/ListBox.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py
index 7213f37d9e..e5f0b825e7 100644
--- a/product/ERP5Form/ListBox.py
+++ b/product/ERP5Form/ListBox.py
@@ -2752,19 +2752,23 @@ class ListBoxValidator(Validator.Validator):
     required_not_found = 'Input is required but no input given.'
 
     def validate(self, field, key, REQUEST):
+        renderer = ListBoxRenderer(field=field, REQUEST=REQUEST)
         form = field.aq_parent
         # We need to know where we get the getter from
         # This is coppied from ERP5 Form
         here = getattr(form, 'aq_parent', REQUEST)
         columns = field.get_value('columns')
-        editable_columns = field.get_value('editable_columns')
         column_ids = [x[0] for x in columns]
+        editable_columns = field.get_value('editable_columns')
         editable_column_ids = [x[0] for x in editable_columns]
+        # Only consider editable columns that the user has selected
+        selected_column_ids = [x[0] for x in renderer.getSelectedColumnList()]
+        editable_column_ids = [x for x in editable_column_ids if x in selected_column_ids]
+
         editable_field_dict = {}
         for sql in editable_column_ids:
           alias = sql.replace('.', '_')
-          editable_field_dict[alias] = ListBoxRenderer(
-                                          field=field).getEditableField(alias)
+          editable_field_dict[alias] = renderer.getEditableField(alias)
 
         selection_name = field.get_value('selection_name')
         #LOG('ListBoxValidator', 0, 'field = %s, selection_name = %s' % (repr(field), repr(selection_name)))
-- 
2.30.9