How to add a non-user-editable field to a content type in Strapi?Real-time “reading time” for blog posts in StrapiHow to use templates in strapiHow do I return only selected certain fields in Strapi?STRAPI - one-way one-to-many relationship in content type builderstrapi, how to migration contentsRestrict file types in Strapi file uploadStrapi : is it possible to track users modifying content?Strapi - prevent 'draft' content from being available to unauthenticated userCustom Validation Message For User Model In StrapiStrapi how to start in background?Strapi - Unable to “Add Content Type”

Exception propagation: When to catch exceptions?

Is Simic Ascendancy triggered by Awakening of Vitu-Ghazi?

Looking for a simple way to manipulate one column of a matrix

What is the significance of 4200 BCE in context of farming replacing foraging in Europe?

Is the schwa sound consistent?

Is there a faster way to calculate Abs[z]^2 numerically?

How do I tell my supervisor that he is choosing poor replacements for me while I am on maternity leave?

How are one-time password generators like Google Authenticator different from having two passwords?

What are the ramifications of setting ARITHABORT ON for all connections in SQL Server?

Renting a house to a graduate student in my department

Why does the Earth follow an elliptical trajectory rather than a parabolic one?

How to make the table in the figure in LaTeX?

Will change of address affect direct deposit?

Can you book a one-way ticket to the UK on a visa?

Help decide course of action for rotting windows

Drawing Quarter-Circle

Should these notes be played as a chord or one after another?

Why does "decimal.TryParse()" always return 0 for the input string "-1" in the below code?

Is "now" UTC time in Solidity?

Two researchers want to work on the same extension to my paper. Who to help?

How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?

Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech?

Why can't RGB or bicolour LEDs produce a decent yellow?

How to pronounce "r" after a "g"?



How to add a non-user-editable field to a content type in Strapi?


Real-time “reading time” for blog posts in StrapiHow to use templates in strapiHow do I return only selected certain fields in Strapi?STRAPI - one-way one-to-many relationship in content type builderstrapi, how to migration contentsRestrict file types in Strapi file uploadStrapi : is it possible to track users modifying content?Strapi - prevent 'draft' content from being available to unauthenticated userCustom Validation Message For User Model In StrapiStrapi how to start in background?Strapi - Unable to “Add Content Type”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Say I have a post content type with the following 4 fields:




  • title (string)


  • content (string)


  • slug (string)


  • author (relationship)

How can I add a 5th field that depends on one of the above 4 fields for its value and isn't user-editable? Say, I wanted a wordCount field with the number of words in the content field as its value. What file should I consider exploring in order to incorporate this functionality?



P.S.: For what it's worth, I'm using MongoDB Atlas for my database needs.










share|improve this question




























    0















    Say I have a post content type with the following 4 fields:




    • title (string)


    • content (string)


    • slug (string)


    • author (relationship)

    How can I add a 5th field that depends on one of the above 4 fields for its value and isn't user-editable? Say, I wanted a wordCount field with the number of words in the content field as its value. What file should I consider exploring in order to incorporate this functionality?



    P.S.: For what it's worth, I'm using MongoDB Atlas for my database needs.










    share|improve this question
























      0












      0








      0








      Say I have a post content type with the following 4 fields:




      • title (string)


      • content (string)


      • slug (string)


      • author (relationship)

      How can I add a 5th field that depends on one of the above 4 fields for its value and isn't user-editable? Say, I wanted a wordCount field with the number of words in the content field as its value. What file should I consider exploring in order to incorporate this functionality?



      P.S.: For what it's worth, I'm using MongoDB Atlas for my database needs.










      share|improve this question














      Say I have a post content type with the following 4 fields:




      • title (string)


      • content (string)


      • slug (string)


      • author (relationship)

      How can I add a 5th field that depends on one of the above 4 fields for its value and isn't user-editable? Say, I wanted a wordCount field with the number of words in the content field as its value. What file should I consider exploring in order to incorporate this functionality?



      P.S.: For what it's worth, I'm using MongoDB Atlas for my database needs.







      strapi






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 10:56









      TheLearnerTheLearner

      63911234




      63911234






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You will have to create your wordCount attribute in your content type.



          Then in the content manager link in the left menu, you will be able to custom the view of your edit/create page. Here you will be able to Disable or Remove the field from the page.



          After that you will have to go in the ./api/post/models/Post.js file and update following functions.



          If you are using NoSQL database (Mongo)



          beforeSave: async (model) => 
          if (model.content) 
          model.wordCount = model.content.length;

          ,
          beforeUpdate: async (model) =>
          if (model.getUpdate().content)
          model.update(
          wordCount: model.getUpdate().content.length
          );

          ,


          If you are using SQL (SQLite, Postgres, MySQL)



          beforeSave: async (model, attrs, options) => 
          if (attrs.content)
          attrs.wordCount = attrs.content.length;

          ,





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312969%2fhow-to-add-a-non-user-editable-field-to-a-content-type-in-strapi%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You will have to create your wordCount attribute in your content type.



            Then in the content manager link in the left menu, you will be able to custom the view of your edit/create page. Here you will be able to Disable or Remove the field from the page.



            After that you will have to go in the ./api/post/models/Post.js file and update following functions.



            If you are using NoSQL database (Mongo)



            beforeSave: async (model) => 
            if (model.content) 
            model.wordCount = model.content.length;

            ,
            beforeUpdate: async (model) =>
            if (model.getUpdate().content)
            model.update(
            wordCount: model.getUpdate().content.length
            );

            ,


            If you are using SQL (SQLite, Postgres, MySQL)



            beforeSave: async (model, attrs, options) => 
            if (attrs.content)
            attrs.wordCount = attrs.content.length;

            ,





            share|improve this answer



























              1














              You will have to create your wordCount attribute in your content type.



              Then in the content manager link in the left menu, you will be able to custom the view of your edit/create page. Here you will be able to Disable or Remove the field from the page.



              After that you will have to go in the ./api/post/models/Post.js file and update following functions.



              If you are using NoSQL database (Mongo)



              beforeSave: async (model) => 
              if (model.content) 
              model.wordCount = model.content.length;

              ,
              beforeUpdate: async (model) =>
              if (model.getUpdate().content)
              model.update(
              wordCount: model.getUpdate().content.length
              );

              ,


              If you are using SQL (SQLite, Postgres, MySQL)



              beforeSave: async (model, attrs, options) => 
              if (attrs.content)
              attrs.wordCount = attrs.content.length;

              ,





              share|improve this answer

























                1












                1








                1







                You will have to create your wordCount attribute in your content type.



                Then in the content manager link in the left menu, you will be able to custom the view of your edit/create page. Here you will be able to Disable or Remove the field from the page.



                After that you will have to go in the ./api/post/models/Post.js file and update following functions.



                If you are using NoSQL database (Mongo)



                beforeSave: async (model) => 
                if (model.content) 
                model.wordCount = model.content.length;

                ,
                beforeUpdate: async (model) =>
                if (model.getUpdate().content)
                model.update(
                wordCount: model.getUpdate().content.length
                );

                ,


                If you are using SQL (SQLite, Postgres, MySQL)



                beforeSave: async (model, attrs, options) => 
                if (attrs.content)
                attrs.wordCount = attrs.content.length;

                ,





                share|improve this answer













                You will have to create your wordCount attribute in your content type.



                Then in the content manager link in the left menu, you will be able to custom the view of your edit/create page. Here you will be able to Disable or Remove the field from the page.



                After that you will have to go in the ./api/post/models/Post.js file and update following functions.



                If you are using NoSQL database (Mongo)



                beforeSave: async (model) => 
                if (model.content) 
                model.wordCount = model.content.length;

                ,
                beforeUpdate: async (model) =>
                if (model.getUpdate().content)
                model.update(
                wordCount: model.getUpdate().content.length
                );

                ,


                If you are using SQL (SQLite, Postgres, MySQL)



                beforeSave: async (model, attrs, options) => 
                if (attrs.content)
                attrs.wordCount = attrs.content.length;

                ,






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 13:46









                Jim LAURIEJim LAURIE

                37615




                37615





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid …


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312969%2fhow-to-add-a-non-user-editable-field-to-a-content-type-in-strapi%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?