MaxLength Attribute

For String fields, MaxLength is the maximum length allowed in the form field. If 0 (default) is specified, MaxLength is inferred from the stored procedure for the save implementation. If specified, MaxLength must be less than or equal to the implementation parameter size.

In the example that follows the table fields are all Length="5":

  1. For FIELD1, the stored procedure parameter is also specified as length 5 and the FormField element does not specify MaxLength. Therefore the default value of 0 is used and MaxLength is inferred from the stored procedure.

  2. For FIELD2, the stored procedure parameter and FormField element are specified as length and MaxLength 4 respectively. The form will accept four characters. Since four is less than the allowed length on the table, there is no conflict.

  3. For FIELD3, the stored procedure parameter is length 6, and MaxLength is 6 on the form field. The form will accept six characters but the table will only accept five. If six characters are entered, the form cannot be saved.

    This creates a conflict.

  4. For FIELD4, the stored procedure parameter is length 6 and MaxLength is not specified. Therefore the default value of 0 is used and MaxLength is inferred from the stored procedure. The form will accept six characters but the table will only accept five. If six characters are entered, the form cannot be saved.

    This creates a conflict.

Table Spec Fields:

  <Fields>
    <TextField Name="FIELD1" Length="5"/>
    <TextField Name="FIELD2" Length="5"/>
    <TextField Name="FIELD3" Length="5"/>
    <TextField Name="FIELD4" Length="5"/>
  </Fields>

Stored procedure parameters for save implementation:

  @ID uniqueidentifier = null output,
  @CHANGEAGENTID uniqueidentifier = null,
  @FIELD1 nvarchar(5),
  @FIELD2 nvarchar(4),
  @FIELD3 nvarchar(6),
  @FIELD4 nvarchar(5)

FormFields element:

    <common:FormFields>
      <common:FormField FieldID="FIELD1"
                        Caption="Field 1"
                        Required="true"
                        DataType="String" />
      <common:FormField FieldID="FIELD2"
                        Caption="Field 2"
                        Required="true"
                        DataType="String"
                        MaxLength="4"/>
      <common:FormField FieldID="FIELD3"
                        Caption="Field 3"
                        Required="true"
                        DataType="String"
                        MaxLength="6"/>
      <common:FormField FieldID="FIELD4"
                        Caption="Field 4"
                        Required="true"
                        DataType="String"
                        MaxLength="4"/>
    </common:FormFields>

Because there are too many characters in Field 3 and Field 4 for the corresponding table columns, the form cannot be saved: