This page is for application designers who want to vary the formatting of components depending on conditions.
Sometimes you want to vary the style of a component depending on some condition. For example, for a form field that:
- has data, you want to apply a style that displays the field background in green
- does not have data, you want to apply a style that displays the field background in red
Use a formatting rule to determine when a style should be applied to an component as follows:
- Open the properties for a component or attribute.
- In the Formatting Rule section, click ; see the Formatting Rule properties for details of all options.
- Enter a Rule Expression to perform a logic check of the data.
- Specify a style. If the expression returns
True
, this style overrides any existing style on the component.- Either select an existing style in the Style box drop-down list.
Alternatively, open the repository to find a style and drag it into the Style box. - Or create a new style, set its properties and save it.
PhixFlow automatically adds a new style to the Style box.
- Save the formatting rule.
Insert excerpt |
---|
| _refresh |
---|
| _refresh |
---|
nopanel | true |
---|
|
the screen, or close and reopen the screen to see the formatting rule applied to the screen.
This page shows how to use formatting rule expressions and styles:
In this example we will set the colour of a cell in a grid where the value is null. In the screenshot below, the null cells are shown in red.
- In the grid header, click a column header to open the attribute properties.
- In the Formatting Rule section, click . PhixFlow opens the new formatting rule properties.
- Enter a Rule Expression.
For this example we want to apply a style when a Web cell is empty. To do this enter the expression:
_current.Web == _NULL
where _current
checks if each row has a value. - Either select a style you want to use, or create a style to apply when the expression is true. Next to the Style drop-down, click . In Basic Settings, set:
- a Name for the style.
- Background Colour: #BF0426.
- Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
to save the style.
- Phixflow automatically adds the new style to the formatting rule → Style.
- Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
to save the formatting rule.
Refresh or reload the page to show the grid with the empty cells of the Web column highlighted in red.
In this example we will set the border of an input field to be red where the value is empty, as illustrated below:
- In the screen canvas, click a field component to open its properties.
- In the Formatting Rule section, click .
- Enter a Rule Expression.
In this example we want a style to be applied when the field is empty. To do this enter the expression:
_value == _NULL
where _value
checks the value in the form field. - Either select a style you want to use, or create a style to apply when the expression is true. Next to the Style drop-down, click . In the style properties → Basic Settings, set:
- Name, for example
MandatoryField
. - Border Style: Solid.
- Border Width:
1px
- Border Colour:
#BF0426
. - Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
to save the style.
- Phixflow automatically adds the new style to the formatting rule's Style.
- Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
to save the formatting rule.
In this advanced example we will set an icon on a card component based on the industry field of our record as illustrated below:
The screen illustrated above has a card container backed by company data. On the card we expect a field called Industry. We want to display a different icon for each industry.
- Upload the images that you want to use as your icons; see Adding Images.
- Create an area on your card component where you will display the images. We will call this the icon area.
- Open the properties for the icon area component.
- Set the area component's size to be suitable for an icon, for example with a Height and Width of 30px.
- To ensure there is never a blank icon area, select an image to display as default. Use
Insert excerpt |
---|
| _property_tabs |
---|
| _property_tabs |
---|
name | style |
---|
nopanel | true |
---|
|
→ Style Settings of
- either a shared style; see Screen Styling
- or directly in the component properties
- Set:
- Background Image: select the image that you want to be the default image if none of the formatting rules are true.
- Background Repeat: None.
- Background Position: Center.
This is CSS so we use the American spelling. - Background Size: Contain.
Contain scales the image as large as possible within its container without cropping or stretching the image. Alternatively, specify a size in px.
- Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
to save the shared style or component.
The following formatting rule checks the industry to determine which icon to display. Create a formatting rule for each of the icons.
- In the Formatting Rule section, click .
- Enter a Rule Expression.
We want to check which industry is on the card to determine which icon to display. To do this enter:
_form.Industry == "Finance"
where _form
checks for the specified value in the Industry
field. - Create a style to apply when the expression is true. Next to the Style drop-down, click . In the style properties → Basic Settings, set:
- Name: for example
FinanceIcon
. - Background Image: select the icon to represent finance.
- Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
to save the style.
- Phixflow automatically adds the new style to the formatting rule's Style.
- Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
to save the formatting rule.
Tip |
---|
You can see an example of this configuration in the Contact Manager demo application (Companies section), which you can download from the Learning Centre Downloads page. |