Thursday, October 15, 2009

Conditional Visibility in Forms

Data Aquarium Framework supports declarative conditional visibility of fields and field categories in form views.

Conditional Visibility of Fields

Here is a snippet of the data field controller used in Code OnTime Designer that controls visibility of the Formula field if the field is marked as computed.

<category headerText="General" >
    <description><![CDATA[ Specify field name, type, and data properties of the field.]]></description>
. . . . .
<dataField fieldName="Computed"> <headerText>The value of this field is computed at run-time.</headerText> </dataField> <dataField fieldName="Formula" columns="50" rows="5"> <visibility> <expression type="ClientScript" test="[Computed]==true"/> </visibility> </dataField> <dataField fieldName="OnDemand"/> </dataFields> </category>

The visibility expression test is written in JavaScript. The expression test can refer to the names of the fields defined in the view. The field referenced must be incased in square brackets.

The expression test is evaluated on the client whenever the field values are changed. Evaluation does not cause the server post-back.

The following screenshots show the form before and after the computed field checked.



Conditional Visibility of Categories

The following snippet from the the same data controller shows visibility expression for a field category.

<category headerText="Lookup">
        <dataField fieldName="ItemsStyle"/>
        <dataField fieldName="ItemsDataController"/>
        <dataField fieldName="ItemsDataValueField"/>
        <dataField fieldName="ItemsDataTextField"/>
        <dataField fieldName="ItemsNewDataView"/>
        <dataField fieldName="ContextFields"/>
        <expression type="ClientScript" test="[Type] != 'Byte[]' &amp;&amp; [Type] != 'Object' &amp;&amp; [OnDemand] != true" />

The JavaScript expression reads as follows:

[Type] != 'Byte[]'  &&  [Type] != 'Object' && [OnDemand] != true

If the value of field Type is not equal to Byte[] or Object and the field is not OnDemand then the category of fields is visible.

The next screenshot shows the visible Lookup field category.



The visibility expressions can be defined directly in the data controller files. The upcoming update to Code OnTime Designer will allow easy modifications of the visibility expressions.


Anonymous said...

How can I set visibility of a table's field in designer ? If it isn't posible, how can I do this in code wich It doesn't need to write visibility tag for each field separately and this process done automaticly?
I saw . I checked "The Value Of This Field …" and wrote my condition in "Furmula" part but generated code wasn't similar with the secend paragraph of the solution that explained in that link. It generates "Formula" tag not "expression" and "visibility" tag.

Customer Service said...

You can control visibility of data fields in and data field categories in designer. Select a data field or a data field category in the view and click on Visibility tab.

You can find more about Code OnTime Generator, Data Aquarium Framework, and other great products here.

© 2010 Code OnTime LLC. Intelligent code generation software for ASP.NET. Visit us at