Table of Contents Previous Section Binding to WOConditionals

Binding to WOConditionals

  1. Select the WOConditional.

  2. Double-click a variable in the variables browser.

A WOConditional displays its contents only if a particular condition is true. WOConditional's main attribute is condition. If condition is 1 (true), the WOConditional's contents are displayed. If condition is 0, the contents aren't displayed. condition can be bound to a variable or to method that returns the 1 or 0 value. The values self or nil also work in place of 1 or 0.

A WOConditional is like an if-then statement in a structured programming language. It tests to see if its condition is true, and if so, it displays its contents. If the condition is false, it displays nothing.

Many times, you want an "else" clause as well; that is, "if the condition is true, display this text; if not, display this other text." In such cases, you can make use of another WOConditional attribute: negate. If negate is 1, it means that the condition is negated after it is evaluated. Thus, if negate is 1 and condition returns 1, the contents are not displayed. To create an if-then-else style of conditional contents, do the following:

  1. Drag two WOConditionals onto the page.

  2. Select the first conditional and double-click a variable in the object browser.

  3. Select the second conditional and double-click the same variable.

  4. In the bindings inspector for the second WOConditional, select the negate attribute, type 1 in the text field in the bindings inspector, and click Connect.

The example below is from a component named ReadWriteString. This component lets you set whether a displayed string is editable using the variable editable. If editable is 1, the component displays the WOTextField contained in the second conditional. The WOString from the first conditional is not displayed because the first conditional negates the value in editable. If editable is 0, the WOString is displayed but not the WOTextField.