InputValidation deprecated

AI-generated summary

The discussion revolves around the deprecation of InputValidation in Discourse, as users migrate from version 2.7.0 to the latest version. piratdavid seeks guidance on replacing InputValidation in their plugins, providing a code example where it’s used for title validation. pfaffman asks for more context, and merefield suggests using git log -SInputValidation -p to find modern alternatives, revealing that EmberObject.create is now used instead. piratdavid appreciates the tip and confirms the approach is simpler than expected, avoiding the need to adopt specific validation classes like name-validation.js.

Hi!

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.

Thanks
David

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.

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 });
    }
  },

Thanks!

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")
         });

<SNIP>

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.