I just looked at the code but I cant see how did you solved this, I am
having the exact problem on another custom widget.

I want a field where users will put recipe ingredients separated by new
lines

*The field*

Field("ingredients", "list:string", requires=LINE_SEPARATED_LIST(),
widget=ListTextWidget.widget)

*on form it is*
*
*
<textarea>------------------

Ingredient number 1
Ingredient number 2
...
...

-------------------------------

*To validate that textarea I created this:*

class LINE_SEPARATED_LIST(object):
    def __init__(self, error_message="value %s is invalid", sep="\n"):
        self.error_message = error_message
        self.sep = sep

    def __call__(self, value):
            items = value.split(self.sep)
            return ([item.strip().replace("\r","") for item in items], None)

*And this widget to create the text area from stored list*

class ListTextWidget(FormWidget):
    _class = 'text'

    @classmethod
    def widget(cls, field, value, **attributes):
        if value:
            value = "\n".join(value)
        else:
            value = ''

        default = dict(value = value)
        attr = cls._attributes(field, default,
                               **attributes)
        return TEXTAREA(**attr)

*The problem is that after validation with errors, the text area becomes:*

<textarea>------------------------------------------------------

['Ingredient number 1', 'Ingredient number 2', ...]

-------------------------------------------------------------------

-- 



Reply via email to