Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Validating input

Widget Connector
width900
urlhttps://www.youtube.com/watch?v=oIRXG6jb7JY&index=14&list=PLbPt6SI1Zhb8CnWh7Gvopto7D6LEwcB9A
height500

Validate input to your application to verify the content being provided. To recap the steps in the video:

Action Validation: Contact Number

Add an action to validate the data typed that users type in for new contacts:.

  1. Open the Contacts stream,.
  2. Go to the section Actions, and add a new action.
  3. Give For the action the following settings, set:
    1. Name: Validate Contact
    2. Display Name: Validate Contact
    3. Go to the

      section

      Action Validation

      Type in the following expression,

      section.
      Enter an expression to check that the phone numbers typed in contain only numbers or spaces

      :

      .

      Code Block
      do (

...

    1. 
          if (!matches(_form.ContactNumber, "[0-9 ]+"),

...

    1. 
              error("Invalid phone number")

...

    1. 
          )
      )

...


    1. Tip

      Raising an error in a validation expression - using the error() function will stop the action at that point.

...

    1. This means the data in the form will not be saved

...

    1. and any other tasks in the action

...

    1. , such as running task plans

...

    1. , will not go ahead.


      • Go to the section Stream Item Action Rules.
        1. Add a Stream Item Action Rule.
          • Add a Stream Action Item and set:
            • Name: Validate Contact
        Set
            • Stream Item Action
        to
            • : Update
        Press
            • Click Apply.
        Tick
            • Copy Values by Name: tick
        1. Save all your changes to the action
        2. Drag the action
    on top of
        1. onto the Add button, and drag the Update button
    on
        1. onto the ContactManager dashboard.

...

Action

...

Validation: Contact

...

Name

Next weWe'll add some additional validation to check that the contacts names have been setentered:

  1. Open the configuration form for the Action Validate Contact.
    You can
    • either open the stream configuration form for Contacts
    , and
    •  and find the list of actions
    ;
    • or click on the Add or Update button
    , and from
    • . From the button configuration form, follow the quick link to the action details.
  2. Add a condition to the Action Validation to check that the FirstName and FamilyName are both set:Add following expression to the existing action validation, .
  3. In the existing Action Validation statement, enter an expression to check that both names are provided:.
Code Block
if ( (isEmpty(_form.FirstName) || isEmpty(_form.FamilyName) ),

...


    error("Please complete both names for the contact")

...


)


Save your changes

...

Final Action Validation will and that completes the configuration. It is useful to see what is going on behind the scenes. Click on the Add button in the configuration. You can see that by dragging the action onto the button, you have set the action for the button to Validate Contact.
Go into App Mode. Type in a new contact and include an invalid character in the telephone number, for example, a letter. This should report an error. You can correct this, then save the new contact. Also test the contact name validation.


The final Action Validation should look like this:

Code Block
do(

...


    // Validate the Contact Number
    if (!matches(_form.ContactNumber, "[0-9 ]+"),

...


        error("Invalid phone number")

...


    ),

	// Validate the Contact Names
    if ((isEmpty(_form.FirstName) || isEmpty(_form.FamilyName)),

...


        error("Please complete both names for the contact")

...


    )

)

...




...

Panel

Next video: 13. Data Types and Formatting