Disabledif (attribute of property)

From JRapid

(Redirected from Disabledif)
Jump to: navigation, search

disableif is an attribute of property.

Contents

Description

The disabledif is used for disabling elements in a form depending on the result of a condition.


The disabledif attribute value is an FPath expression that must return a boolean result. This expression enables the developer to query the current value of the form properties in order to check a condition.

Usage

<property
   ...
   disabledif="FPATH_CONDITION"
   ...
/>

Examples

  • A common condition for disabling properties in a form is depending on a boolean property.

The following example is based on an Attendee entity. This example shows how a property of type text, intended for detailing the members of a group, is enabled only when the boolean property "withgroup" is marked as true for an attendee.

Note that the condition checks for the empty value first, as the "withGroup" boolean property has a null value when the form is opened for a new Attendee.

 <entity label="Attendee" menu="Menu" name="Attendee">
    <property display="primary" label="First Name" name="firstName"/>
    <property display="primary" label="Last Name" name="lastName"/>
    <property label="Group" name="withGroup" type="boolean" />
    <property label="Group Members" name="groupMembers" type="text" disabledif="withGroup = '' or withGroup = 'false'" />
 </entity>


Disabledif condition with boolean example
  • Other possibility is to disable a property field depending on a number entered for another property in the same form.

Next form shows how a property of type entity Delivery is only disabled as long as the number of items sold is less or equal to five.

Note that you need to replace the < character for &lt; to keep the XML valid.

 <entity label="Sale" menu="Menu" name="Sale">
    <property display="primary" label="Date" name="saleDate" type="date"/>
    <property label="Number of Items" name="numberOfItems" type="integer"/>
    <property entity="Delivery" label="Delivered by" name="delivery" disabledif="numberOfItems = '' or numberOfItems &lt;= 5" />
 </entity>


Disabledif condition with integer example
  • Another common situation in which you may need to disable a property on a form is depending on if the value for that same property has been set or not. This is, once a value is selected for a property, disable it so that it cannot be edited.

There are some variations on how this can be achieved, depending on the property type.

For an integer property, you may use the following expression.

    <entity label="Rating" name="Rating">
        <property display="primary" label="Team" name="team"/>
        <property disabledif="rateValue != ''" label="Rate Value" name="rateValue" type="integer"/>
    </entity>

So you get the property input enabled when the value is not set, and disabled once it has been set an saved.

Disable property depending on its own value


For an entity type property, the expression to be used is the following.

    <entity label="Genre" menu="Menu" name="Genre">
        <property display="primary" label="Name" name="name"/>
    </entity>

    <entity label="Album" menu="Menu" name="Album">
        <property display="primary" label="Artist" name="artist"/>
        <property display="primary" label="Title" name="title"/>
        <property entity="Genre" label="Genre" name="genre" disabledif=". > 0" />
    </entity>

The expression ". > 0" evaluates the id of the value selected for the genre property. If it is greater than zero, then a value has been set. The following image shows how an existing and a new Album forms are shown.

Disable entity type property depending on its own value

If the property is of entity type, but a combo widget is being used, then the expression changes to the following.

    <entity label="Genre" menu="Menu" name="Genre">
        <filter display="primary" label="Name" name="name" property="name"/>
        <property display="primary" label="Name" name="name"/>
    </entity>

    <entity label="Album" menu="Menu" name="Album">
        <property display="primary" label="Artist" name="artist"/>
        <property display="primary" label="Title" name="title"/>
        <property comboproperty="name" entity="Genre" label="Genre" name="genre" widget="combo" disabledif=". != ''" />
    </entity>

And again, the new and existing Album forms are shown.

Disable entity type property with combo widget depending on its own value

See also

Personal tools