Dan Jacob a écrit :
I can think of one possible case: you have a shopping cart form
consisting of a variable number of TextField widgets for the quantity
of each item in your form. Each widget requires the Int validator. How
would this be handled with stateless forms and widgets ?



> I can think of one possible case: you have a shopping cart form
> consisting of a variable number of TextField widgets for the quantity
> of each item in your form. Each widget requires the Int validator. How
> would this be handled with stateless forms and widgets ?

Prof of concept in pseudo-python (currently in dev in my box) :

class WidgetCloneComposite(Widget):

        def __init__(name, widgetPrototype):
            """
            :param name: the name of the widget
            :type name: string
            :param widgetPrototype: the prototype of widget to clone
            :type widgetPrototype: a Widget's instance
            """
            pass

        def input(self, values):
            """
            for each group of values starting with same  <name>.<number>.",
                create a dict without prefix
                call widgetPrototype.input(subValues)
                aggreate result with existing.
            return aggregated result
            """
            pass

        def insert(value, input_values,...):
            """
            create a list with clones of widgetPrototype :
              * renamed with a prefix <name>.<number>.
              * call insert on every clone with value extracted (see input())
            """
            pass

        def retreive_css():
            return widgetPrototype.retreive_css()

        def retreive_javascript():
            return widgetPrototype.retreive_javascript()


Next you could create (if you need) a Decorator that modify input() to assemble the item of list in an table, div or anything else.

It's the solution, I currently implements for my widget library (plubished near)

--
--------------------------------------------------------------
David "Dwayne" Bernard            Freelance Developer
                                  mailto:[EMAIL PROTECTED]
      \|/                         http://dwayne.java-fan.com
--o0O @.@ O0o-------------------------------------------------

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to