CheckUniqueConstraint and context-sensitive alerts

Smartsite 7.9 - ...

As of  Smartsite 7.9, the DataEditor (generator) supports two more options (on the textbox control):

  • Check unique constraint for a specific field.
  • Context-sensitive alerts.

Both options could already be programmed using a custom control + custom XForms logic (like explained in Adjusting the DataEditor xml), but as of 7.9 the DataEditor adds the necessary XForms logic just by specifying the appropriate properties.

CheckUniqueConstraint

The checkuniqueconstraint property will add the XForms logic needed to check the unique constraint for a specific field. It will invoke the checkuniqueconstraint extension function when the value of the input changes and set the XForms constraint property for the field accordingly.

Context-sensitive alerts

When the XForms Engine marks a field as invalid, there are multiple reasons why the field could be considered invalid:

  • The field is required and no input has been given.
  • The given input does not comply to the constraint rule(s) (if any).
  • The given input does not comply with the schema type (if a schema type has been set).

To give the user an accurate reason why the field fails to validate, as of 7.9, you can now specify three alerts for each of the above mentioned situations, respectively:

  • alert_required_invalid
  • alert_constraint_invalid
  • alert_schema_invalid

These three alert messages will be written to the state instance into three nodes and the textbox's alert element will include three output elements referencing these nodes. Bind rules will be added to set each of these three nodes relevant, based on the validation result of the field.

Notice that you can also specify just two of these alert types, e.g. when there's no schema type set on the field or when there is/are no constraint rule(s).

Example

The example below shows you how to include these properties within the field definition of a DataEditor xml definition.

XML CopyCode image Copy Code
<field name="code">
  <control type="textbox">
    <properties>
      <property name="required">true</property>
      <property name="maxlength">20</property>
      <property name="alert_required_invalid">{text:CODE_REQUIRED}</property>
      <property name="alert_constraint_invalid">{text:CODE_DUPLICATE}</property>
      <property name="alert_schema_invalid">{text:CODE_INVALID}</property>
      <property name="checkuniqueconstraint">true</property>
    </properties>
  </control>
</field>

The result will be something like the examples shown below.

Alert_required_invalid example

Alert_constraint_invalid example

Alert_schema_invalid example