Conditions

Conditions

You can use any Appcelerator message as a condition. Here’s an example:

on="r:items.response then [action]"

In the example above, the action will be executed when the message r:items.request is received.

You can also look for specific values in the data payload of the message.

on="r:items.response[success=true] then [action]"

Then that action will only be executed if the message has a parameter success with the value true.

Other examples of parameters include

on="r:items.response[success!=false] then [action]"
on="r:items.response[success] then [action]"

Standard DOM Events

Key Events

These work just like the DOM key events provided by browsers, except that you can specify a keycode as part of the condition. For example you can use ‘esc’ or ‘enter’ or you can match for the exact keycode like ‘49’.

<input type="text" on="keyup[esc] then [action]"/>

You can also match for ctrl, alt, or shift combinations.

<input type="text" on="keyup[ctrl+shift+49] then [action]"/>

History Event

The history event happens when there is a browser history event, triggered by an anchor (#) in the URL. This can be used to help support bookmarking capabilities within an RIA.

For example, http://localhost:3000/index.html#form will trigger a history event that can be used in a condition such as

on="history:form then [action]"

You may also catch all history events by using a wildcard

on="history:* then [action]"

In the wildcard case, to see what history state was triggered, you can use the this.data.state variable in your action.

iPhone Events

Other Events