Input Validation

Slack modals provide input validation for elements that are contained in input components. Error messages are displayed when the modal is submitted.

While Slack provides some client-side validation in Slack apps, we recommend that you run input validation based on your app’s business logic. For example, Slack displays an error message on an empty required field when you try to submit a form.

Required field displays an error

Apex SDK for Slack’s field-level validation enables you to handle additional checks on your user input, displaying any errors on form submission.

Field-Level Validation 

Specify the data type for an input component that’s used to automatically validate the format of the element value entered by the user. If validation fails, an error message is displayed.

To validate the input value, use the type property of the containing input component.

1description: "Validation Test"
2components:
3  - definition: modal
4    properties:
5      title: "Create Order"
6    components:
7      - definition: header
8        properties:
9          text: "Quantity"
10      - definition: input
11        name: "number_input" # The optional name for the input type
12        properties:
13          label: "Number"
14          type: "number" # The type used for validation
15          required: true
16        components:
17          - definition: textInput
18            properties:
19              name: "number"
20              placeholder: "Enter a number"

If the textInput does not contain a valid number, user submission is aborted and an error message appears below the input element.

Number field displays an error

Apex SDK for Slack offers a set of types that describe the expected format of an input value based on the user locale in the Salesforce org.

  • currency
  • email
  • number
  • url

Currency 

The currency locale in the Salesforce org determines if a currency input is valid. Currencies are valid with or without a currency symbol or ISO currency code. The numeric value supports grouping separators and decimal symbols depending on the locale.

For example, $1,025.7 is valid when the currency locale is English (US) and £1,025.7 is valid when the currency locale is English (UK).

To see your org’s currency locale, from Setup, click Company Information. On the Company Information page, find the Currency Locale field. The currency local is global and impacts all users on the org.

Email 

A valid email follows the pattern username@domain.com or user.name@domain.com.

Here are a few examples.

  • Valid: example@domain.com or example+group@domain.com
  • Invalid: example@domain or example name@domain.com

Number 

The user locale determines if a number input is valid. For example, 12,345 is valid when the locale is English. But 1.025,7 is valid only if the locale is German or Dutch.

Here are a few examples based on the English locale.

  • Valid: 1.00, 1,000, or 1,000.00
  • Invalid: 1.2.3

URL 

A valid URL includes a protocol followed by the domain name and optional parameters. Unicode domains are not supported.

Supported protocols include http://, https://, ftp://, ftps://, and many others like mailto: and news:. Anchor links are supported.

Here are a few examples.

  • Valid: http://www.salesforce.com or https://example.com?testKey=testValue
  • Invalid: salesforce.com or www.salesforce.com

Validation Considerations 

Using Apex code to validate user input is not yet supported.

Validation using Apex code is subject to Slack’s three seconds acknowledgment response. Otherwise, the user receives a connection error in the modal. Dependent field validation is not currently supported if it involves a call to Salesforce.

These field types are not yet supported.

  • Multicurrency
  • Geolocation
  • Phone number
  • Text

Beta Feature

This feature is not generally available. It is not part of your purchased Services. This feature is subject to change, may be discontinued with no notice at any time in SFDC’s sole discretion, and SFDC may never make this feature generally available. Make your purchase decisions only on the basis of generally available products and features. This feature is made available on an AS IS basis and use of this feature is at your sole risk.