Rule
The Rule component triggers a rule when another SPEAK component raises an event. You specify the component and the event that make the Rule component trigger a rule.
A rule consists of a condition and an action. You create a rule by creating a Rule item based on the RuleDefinition template. You connect the Rule component to a Rule item in the RuleItemId property of the Rule component.
You add a Rule component to your page for each event that you are interested in, and a page can have multiple Rule components. Several different Rule components can point to the same Rule item.
SPEAK executes the rules of a page after the page code has finished executing.
Properties
| Name | Description | Default |
|---|---|---|
| Data | ||
| Field | Specify the name of the field in the rule item that contains the rule configuration. SPEAK sets the value to “Rule”, and you should not change it. | Rule |
| RuleItemId | Point to the rule item that contains the conditions and the actions of this rule. | |
| TargetControl | Specify the ID of the SPEAK control that the Rule component listens to for the event specified in the Trigger property. | The Rule component listens to the “window” for events if you do not specify a control. |
| Trigger | Specify the event that triggers the rule. You can specify an event (“change”), or an event and an attribute (“change:text”). |
Configuration
To specify the event that triggers a rule:
- Specify the ID of the SPEAK component that you want to “listen” to in the TargetControl property.
- Specify the event in the Trigger property. You can specify just the event (for example: “
change”, or “click”), or you can specify an event and an attribute (for example: “change:facets”). If, for example, you specify “change:facets”, the Rule component triggers a rule when the component raises the “change” event for the “facets” attribute.
The default component is “window.” This means that if you do not specify a component, the Rule component listen for events raised by the “window” component. The “window” component is the dialog page itself. It has a “resize” event.
Components can have specific events, but all components have a “change” event. You can use a combination of the “change” event, an attribute, and the Rule condition to precisely specify when a rule is executed.
You can create a configuration item for a Rule component by creating an item based on the Rule Parameters template.
The configuration item has these specific fields:
- Trigger
- RuleItemId
- Field
- TargetControl
It inherits these fields:
- Behaviors
- Id