Self-references in formula

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Self-references in formula

Bernat Romagosa
Hi list,

Imagine I have to validate a field depending on another field, like in the following example:

|anObject|
formula := ILFormula on: anObject.
(formula inputOn: #whatever).
(formula inputOn: #something)
   addCondition: [:v | v hasSomethingToDoWith: anObject whatever].

I understand the non-triviality of the problem, as anObject isn't complete until the form is submitted. However, my case really requires one field to be validated against another... is there a way to implement such behaviour in Formula?

Thanks again!

Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: Self-references in formula

Nicolas Petton
Hi,

You can add global conditions to the formula for that.
The following example adds 2 fields and checks if their values are the
same.

formula := ILFormula on: aModel.

formula inputOn: #foo.
formula inputOn: #bar.

formula addCondition: [:model |
        model foo = model bar]


Note that the model parameter in the condition block is in fact a proxy,
not the model itself. It will be committed to the model only if all
conditions are validated.

HTH,
Nico
Le vendredi 25 mars 2011 à 18:24 +0100, AxiNat a écrit :

> Hi list,
>
>
> Imagine I have to validate a field depending on another field, like in
> the following example:
>
>
>         |anObject|
>         formula := ILFormula on: anObject.
>         (formula inputOn: #whatever).
>         (formula inputOn: #something)
>            addCondition: [:v | v hasSomethingToDoWith: anObject
>         whatever].
>
>
> I understand the non-triviality of the problem, as anObject isn't
> complete until the form is submitted. However, my case really requires
> one field to be validated against another... is there a way to
> implement such behaviour in Formula?
>
>
> Thanks again!
>
>
> Bernat Romagosa.


Reply | Threaded
Open this post in threaded view
|

Re: Self-references in formula

Bernat Romagosa
Thanks Nico,

This solves not only this particular situation, but other problems I thought I'd find myself into in the future :)

Bernat Romagosa.