InputValidation deprecated


I’m migrating a rather old forum version (2.7.0) to the latest discourse version. One problem I’m encountering is that ‘discourse/models/input-validation’ seems to be removed. Could someone guide me to migrate this to whatever solution is accurate now. It seems that input validation is done pretty different now.


It this in some plugin that you wrote? Maybe share a link to it if that’s possible.

Or what it is that you’re trying to validate.

1 Like

Hi! Yes sorry it’s a number of plugins. It’s in a private git repo but I could send code examples.

 @computed('model.title', 'lastValidatedAt')
  titleValidation(title, lastValidatedAt) {
    if(this.model.get('titleMissing') && !title) {
      return InputValidation.create({ failed: true, reason: I18n.t('news.error.title_missing'), lastShownAt: lastValidatedAt });


So a little trick for you (which isn’t particularly Discourse specific btw):

In your dev discourse directory do:

git log -SInputValidation -p

And :tada: , you can immediately see a potentially modern equivalent!:

-import InputValidation from "discourse/models/input-validation";
+import EmberObject from "@ember/object";

 export default Controller.extend({
   adminWebHooks: inject(),
@@ -41,14 +41,14 @@ export default Controller.extend({
   secretValidation(secret) {
     if (!isEmpty(secret)) {
       if (secret.indexOf(" ") !== -1) {
-        return InputValidation.create({
+        return EmberObject.create({
           failed: true,
           reason: I18n.t("admin.web_hooks.secret_invalid")

1 Like

Great! I figured I might be able to find git changes related to that but I’m not really a git genie. Thank you! That will help a lot. I thought I had to start using the more specific validation classes that exist, name-validation.js etc. This looks easy enough.