Validation Xbasic

Description

Specify Xbasic code to test if the data in this field is valid.

An error message generated using Xbasic

By default, only dirty fields are validated. You can specify that all fields should be validated in Update Settings, Edit Properties. If this field is a Repeating Section, see the setting in the Repeating Section for 'Validation - field option' and 'Validation - row option'.

Using Validation Xbasic 

  1. In the UX Builder on the UX Controls page open the 'Data Controls' menu. Click on the [TextBox] option to add a textbox control to the component. Give the control the name 'firstname' and the label 'First name'.

  2. Click on the [TextBox] option again to add a second textbox control. Give this textbox the name 'lastname' and the label 'Last name'.

  3. Highlight the lastname textbox. In the properties list on the right click the ... button next to the 'Validation rules' property in the Field Properties section.

  4. Check the 'Enable rules' checkbox.

  5. In the 'Text Format' section of the 'Field Validation' dialog check the 'Allow letters' and 'Allow whitespace' checkboxes. Click OK.

  6. Click the ... button next to the 'Validation Xbasic' property.

  7. Define the following Xbasic for the validate_lastname() function and click OK.

    function validate_lastname as p (e as p)
    if e.data.lastname = "Smith" then
    	validate_lastname.hasError = .t.
    	validate_lastname.errorText = "Last name value can't be Smith."
    end if
    end function
  8. Open the 'Defined Controls' menu and click on the 'Submit-Reset' option to add submit and reset buttons to the component.

    When you click the submit button an Ajax callback will be made.
  9. Run the component in Live Preview. Enter 'Smith' into the Last name textbox and the Xbasic error message should fire.

See Also