Reload data after saving update

As suggested at that github issue (lifecycle hooks not working in Collections with draft/publish-System · Issue #8329 · strapi/strapi · GitHub) I like to discuss my problem here.
I have my own slug field which is generated beforeCreate and beforeUpdate. With the introduction of the draft/publish-system my code was not working, because on publishing only the published_at field is present in data, because pressing the “publish”-button only puts this field. I came up with the solution to check if a mandatory field is present in the data-object. If yes the “save”-button was pressed, beacuase than all fields are in the data-object. So I do not have to make anaother query with params:id:

'use strict';
const slugify = require('slugify');
const { default: createStrapi } = require('strapi');

const mySlugify = (slug) => { 
  return (
    slugify(slug, { 
      remove:/[*+~.(){}\[\]\\/'"!:@,]/g, 
      lower:true 
    })
  );
};

/**
 * Lifecycle callbacks for the `product` model.
 */

module.exports = {

  lifecycles: {
    async beforeCreate(data) {
      if (data.orderno) {
        if (!data.name_en) {
          data.name_en = data.name_de;
        }
        data.slug_de = mySlugify(data.name_de + '-' + data.orderno);
        data.slug_en = mySlugify(data.name_en + '-' + data.orderno);
      }
    },

    async beforeUpdate (params,data) {
      if (data.orderno) {
        if (!data.name_en) {
          data.name_en = data.name_de;
        }
        data.slug_de = mySlugify(data.name_de + '-' + data.orderno);
        data.slug_en = mySlugify(data.name_en + '-' + data.orderno);
      }
    },

  }
};

My problem is, that the data form is not refrehed immediatly after save, like at the first creating.
The changes are only shown after closing the form and opening it again.

Is there a way to refresh the shown data after updating?

1 Like

Because of where this change happens (right before the data is sent to the database, thus already in the backend) we couldn’t do something cheeky on the frontend other than add some logic to the save button to refresh the content.

@soupette and @HichamELBSI do you guys have some suggestions on modifying the logic behind the save button in the Content-Type Manager?

Hello,

You can override this file however, I don’t recommend it because you will have an harder time upgrading your app when we publish new changes. Instead, I think that you should open an issue so we can take care of fixing this bug. The bug is indeed the following one, we should have an submit success case where we should re populate the form with the data that was just submitted.

Thanks. I will wait and keep strapi update save.
Bug report is done:
https://github.com/strapi/strapi/issues/8400

3 Likes

Hey guys,

@soupette is there any feedback about when this change could be implemented? I haven’t see anything on the roadmap.

Many thanks in advance for your help :slight_smile:

It will be fixed with the following PR

3 Likes