2006/11/2, Ramon Leon <ramon.leon(a)allresnet.com>om>:
Anyone know of any good resources for working with the
validation system of
Magritte. Specifically I'm interested in what it takes to have fields that
depend on the value of each other. Say an end date that must be before a
start date, both of which have just been edited.
I was thinking something like this on the instance side...
description
^self class description collect: [:each |
each accessor selector = #eventEndDate
ifTrue: [each addCondition: [:value | value > self
eventStartDate]]
ifFalse: [each]]
But that doesn't work because I can't rely on eventStartDate having a value
yet, it may not have been set by its description, or it may be invalid for
some other reason. Are the any public sample apps that use Magritte heavily
one could look at?
I need something like that for events in ICalMagritte where either
duration or end has to be nil. I define a condition on the object
(event) like this:
MACondition subclass: #ICMEventCondition
value: aCheckedMemento
^(self endOf: aCheckedMemento) isNil
or: [ (self durationOf: aCheckedMemento) isNil ]
endOf: aCheckedMemento
^aCheckedMemento cache at: ICEvent descriptionEnd
durationOf: aCheckedMemento
^aCheckedMemento cache at: ICEvent descriptionDuration
ICEvent class >> #descriptionContainer
^super descriptionContainer
addCondition: ICMEventCondition new labelled: ICMEventCondition defaultLabel;
yourself
There are probably better ways but this works nice for me.
Cheers
Philippe