Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.kibocommerce.com/llms.txt

Use this file to discover all available pages before exploring further.

A field validator helps you ensure the user input meets specific requirements and matches the expected format for a field. In this tutorial, we will learn how to add validators to a content model’s fields. As an example, we will add validators to the LONG TEXT and NUMBER fields used in the Product content model that we created in the Create Content Model tutorial.

Step 1: Add Required and Min length validators to a LONG TEXT field

In this step we will:
  • make the Description field required.
  • set the minimum length for the input the Description field to 20 characters.
  1. From the Side Menu, Click Content Modeling > Models.
    The Content Models screen opens.
  2. Hover over the Product content model.
  3. Click Edit.
    Screen to configure the Product content model’s fields opens.
  4. Click the Edit Field icon on the Description field.
    Field Settings - Long Text screen opens.
  5. Click the Validations tab.
  6. Enable the Required validation by toggling the Enabled button. This will make the Description field mandatory.
    Message textbox will appear to set the error message.
  7. In the Message textbox, type Please enter the product description.
  8. Enable the Min length validation by toggling the Enabled button.
    Message and Value textboxes will appear to set the error message and minimum value.
  9. In the Message textbox, type Description cannot be less than 20 characters.
  10. In the Value textbox, type 20.
  11. Click Save Field.
    Screen to configure the Product content model’s fields opens.
  12. Click Save.
    The message “Your content model was saved successfully!” displays.

Step 2: Test the validators

  1. On the screen to configure the Product content model’s fields, click the Preview tab.
  2. Click the Description textbox.
  3. Click anywhere outside the Description textbox.
    The message “Please enter the product description” appears.
  4. In the Description textbox, type Top sweatshirt.
  5. Click anywhere outside the Description textbox.
    The message “Description cannot be less than 20 characters” appears.