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;
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
add a comment |
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
add a comment |
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
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
strapi
asked Mar 23 at 10:56
TheLearnerTheLearner
63911234
63911234
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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;
,
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
,
add a comment |
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;
,
add a comment |
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;
,
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;
,
answered Mar 25 at 13:46
Jim LAURIEJim LAURIE
37615
37615
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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