discourse/docs
Isaac Janzen 69193c4bd5
DEV: Add a callback to the validation of user custom fields in the signup form (#27369)
# Description

Add `addCustomUserFieldValidationCallback` to the user fields validation mixin. This allows you to add a custom validation when checking the validity of custom user field values in the signup form on submit. 

```js
addCustomUserFieldValidationCallback((userField) => {
  if (userField.field.name === "my custom user field" && userField.value === "foo") {
    return EmberObject.create({
      failed: true,
      reason: I18n.t("value_can_not_be_foo"),
      element: userField.field.element,
    });
  }
});
```

In the case your custom validation deems an input value `failed`, you return an EmberObject with the fields `failed: true`, `reason`, and `element`.

```js
return EmberObject.create({
  failed: true,
  reason: I18n.t("value_can_not_be_foo"),
  element: userField.field.element,
});
```

which will then display your custom `reason` to the user attached to the given user custom field input and will not submit the signup form.

<img width="288" alt="Screenshot 2024-06-06 at 11 08 40 AM" src="https://github.com/discourse/discourse/assets/50783505/11168fb8-8806-43f0-9417-73991bbd1178">

# Other

- Add `addCustomUserFieldValidationCallback` to the plugin api
- Bump plugin api version
- Update plugin api changelog
- Add tests
2024-06-06 11:17:06 -06:00
..
ADMIN-QUICK-START-GUIDE.md FIX: uses the correct link for the General category (#26891) 2024-05-07 13:42:58 +02:00
AUTHORS.md HTTPSify links (#7046) 2019-02-22 16:29:27 +01:00
CHANGELOG-JAVASCRIPT-PLUGIN-API.md DEV: Add a callback to the validation of user custom fields in the signup form (#27369) 2024-06-06 11:17:06 -06:00
code-of-conduct.md Update Code of Conduct to v2.0 (#12296) 2021-03-04 23:44:58 -05:00
DEVELOPER-ADVANCED.md Update DEVELOPER-ADVANCED.md (#15770) 2022-02-02 11:05:37 -05:00
DEVELOPMENT-OSX-NATIVE.md DEV: Swap out optipng with oxipng (#15013) 2021-11-22 10:16:35 -07:00
INSTALL-cloud.md Update INSTALL-cloud.md screenshots and copy when landed on the forum homepage (#25671) 2024-02-14 07:31:44 -07:00
INSTALL-email.md DOCS: Update INSTALL-email to point to Brevo correctly 2023-12-04 11:46:33 +11:00
INSTALL.md DEV: Update recommended Ruby to 3.2.1 (#20444) 2023-02-24 12:51:34 -03:00
PLUGINS.md discourse/discourse change from 'master' to 'main' 2021-07-19 11:46:15 -04:00
SECURITY.md FEATURE: Increase pbkdf2 iterations to 600k (#20981) 2023-04-11 11:56:20 +01:00
TESTING.md DEV: replace mailcatcher references with mailhog (#14500) 2021-10-05 15:48:06 +05:30
TROUBLESHOOTING.md for docs, normalize on space after code fence when specifying lang 2019-01-21 01:19:28 -08:00