1 Dec 2008 01:53
Strange inline validation error in formlib SelectWidget
Hi all, in a project based on collective.tin, I cannot overcome an annoying problem with the "missing_value" option in the formlib SelectWidget. In several add and edit views, I have Choice fields - with dynamically generated vocabulary - whose value is not required They are added/edited with a SelectWidget that includes a "missing_value" option, whose label, in English, is "(no value)". In all of them, when the user selects the missing_value option, and then moves the focus outside, thus causing a "blur" event, the inline validation yields an "invalid value" error message, but then s/he can save the form without getting further validation error. I've investigated a little what happens in the modules zope/app/form/browser/widget.py and zope/app/form/browser/itemswidgets.py When the method _toFieldValue of the class SingleDataHelper is executed, in module itemswidgets, during inline validation, if the missing_value option is selected, it turns out that the value of the "input" argument IS THE VALUE OF THE CONTENT OF THE HTML "option" element, that is the "(no value)" label, instead of the value of its "value" attribute, that is an empty string. Obviously "(no value)" is not null and is not a value in the vocabulary; thus the method convertTokensToValues raises an InvalidValue exception and, in turn, _toFieldValue raises a ConversionError. The "input" argument of _toFieldValue comes from the execution of _getFormInput() in the getInputValue method of the SimpleInputWidget class in the widget module.(Continue reading)
On Nov 30, 2008, at 10:27 AM, Espen Moe-Nilssen wrote:
RSS Feed