Skip to content
Sean DeNigris edited this page Mar 25, 2018 · 1 revision

Field Relationships

When a Condition depends upon multiple fields, the pattern is to add it to the container description. For example:

descriptionContainer
	^ super descriptionContainer	
		addCondition: [ :obj | (obj readUsing: self descriptionIncludesDay) or: [ obj readUsing: self descriptionIncludesNight ] ]
		labelled: 'Neither day or night is selected'
		yourself

You'll notice that fields are accessed via #readUsing: and not directly via their getter messages. This is because obj may be either your domain object (e.g. via maValidate) or a Memento object representing it (e.g. via a Magritte form). #readUsing: is polymorphic and will work in either context, unlike getters which will only work on the domain object, or cache at: which will only work on MACachedMementos.

Inter-Condition Dependencies

There are situations when it only makes sense to validate a condition if another condition has passed. For example, say I want to see if a date is a holiday. That would only make sense if date was valid. We recently added MADescription>>#addCondition:labelled:ifValid: to handle this case[1]. Just pass the description depended on as the last argument.

  1. Before there was a formal way to declare this in the API, in such cases, one could use a guard like the following addCondition: [ :obj | ("check dependency") or: [ "validation requiring a date" ]
Clone this wiki locally