[html-formfu] RFC: enhanced when

Mario Minati mario.minati at googlemail.com
Sun Oct 28 10:39:36 GMT 2007


On Wednesday 24 October 2007 20:06:28 Jonas Alves wrote:
> Hi all,
>
> I would like to enhance the "when" attribute to accept something like this:
>
> - type: Password
>     name: password2
>     label: Retype Password
>     constraints:
>              - type: Equal
>                others: password
>                when:
>                  field: password
>              - type: Required
>                when:
>                  stash: is_create
>                  value: true
>
>
> So when the "when" attribute receives a "field" attribute without a
> "values" attribute it returns true if the field is filled. Another enhance
> is to receive a "stash" attribute that works like the "field" attribute but
> checks the stash instead. However it makes it impossible to use both
> "field" and "stash" attributes at the same time because the "values"
> attribute can't work for both at the same time. To handle that we can make
> "field" and "stash" accept an hash ref. The config would look like:
>
>     when:
>         field:
>             name: foo
>             values: [1, 2, 3]
>         stash:
>             name: bar
>             values: [4, 5, 6]
>
> And it would do an intersection between the two. If we need an union it
> could be something like this:
>
>     when:
>         - type: field
>           name: foo
>           values: [1, 2, 3]
>         - type: stash
>           name: bar
>           values: [4, 5, 6]

I'd rather go for 

    when:
	- conditions:
            - type: fieldname
              name: password
            - type: values
              name: foo
              values: [1, 2, 3]
	- conditions:
            - type: stash
              name: bar
              values: [4, 5, 6]

Within each condition section the entries are concatenated with AND. The 
condition sections themselfes are ORed.


>
> Another thing that I miss is a way to specify how I want the values to be
> compared. Sometimes I don't want to use "eq" and a regex would be more
> appropriated:
>
>     when:
>         field:
>             name: foo
>             regex: /^\d+$/

Providing regex is fine.


Greets,
Mario



More information about the HTML-FormFu mailing list