Discourse Authentication Validations

:discourse2: Summary Discourse Authentication Validations enables the ability to add custom validations to a User Field to toggle the display of User Fields on the Signup Modal.
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-authentication-validations
:open_book: Install Guide How to install plugins in Discourse

:information_source: About

Discourse Authentication Validations adds the ability to add custom validations to a User Field.

Custom User Fields do not have any type of validation provided by core, outside of detecting an empty value on a required field. This plugin adds the ability to define a regex, per user field, that will then be checked against the provided input value.

Additionally, this plugin adds the ability to toggle the display of User Fields on the Signup Modal. This allows you to “chain” User Fields together, so that a User Field is only displayed if a previous User Field has a specific value.

:building_construction: Basic Setup

1. Enable Plugin

The Discourse Authentication Validations plugin can be enabled either by the toggle or from its settings, both accessible from your admin/plugins page.

2. Add a custom validation to a User Field

After the Discourse Authentication Validations plugin has been enabled you will see a Include a Custom Validations checkbox at the bottom of your User Field form.

When checked it will display an additional three fields:

  1. Value Validation Regex
  2. Show Values
  3. Target User Fields

:closed_lock_with_key: Adding a Custom Validation

Include a valid regex in the Value Validation Regex field:

The user field’s value on the signup form will now be tested against the regex you have included. In the case that the input does not meet the standards of your custom Regex, the signup form will not submit.

No value (relies on default form validation)

Incorrect value

Correct value

:link: Chaining User Fields

Firstly, include a Show Values value on a User Field.

When a User Field has a Show Values value included it will watch the value of the attached input until the input value matches ANY of the show values. It will then toggle the visibility of any included Target User Fields, making them visible.

Secondly, add a Target User Fields value.

In the Target User Fields dropdown you will see a list of all available User Fields. Any User Field you select will have their visibility toggled by corresponding values in Show Values.

:hammer_and_wrench: Advanced Chaining

You can chain User Fields together by adding custom validations to multiple User Fields.

For example, let’s say we have three User Fields with the given values:

Name Has Custom Validation Show Values Target User Fields
Input One true show-field-two Input Two
Input Two true show-field-three Input Three
Input Three false

Input Two and Three will be hidden by default as they are “children” of Input One. When the show value of show-field-two is added to Input One, Input Two will be displayed, but Input Three will still remain hidden. It will remain hidden until Input Two has the value of show-field-three.

With the correct combination of Show Values and Target Classes you can infinitely nest User Fields beneath each other.

15 Likes