{"id":41853728,"url":"https://github.com/voorhoede/datocms-plugin-computed-fields","last_synced_at":"2026-01-25T10:34:44.619Z","repository":{"id":38086341,"uuid":"304599262","full_name":"voorhoede/datocms-plugin-computed-fields","owner":"voorhoede","description":"This DatoCMS plugin allows to compute and define a field value based on other fields.","archived":false,"fork":false,"pushed_at":"2023-08-11T13:15:13.000Z","size":4108,"stargazers_count":4,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-03T12:54:03.761Z","etag":null,"topics":["computed-fields","datocms-plugin","open-source"],"latest_commit_sha":null,"homepage":"https://www.datocms.com/marketplace/plugins/i/datocms-plugin-computed-fields","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voorhoede.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-16T10:52:13.000Z","updated_at":"2023-07-11T11:16:23.000Z","dependencies_parsed_at":"2023-02-01T02:31:28.968Z","dependency_job_id":null,"html_url":"https://github.com/voorhoede/datocms-plugin-computed-fields","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/voorhoede/datocms-plugin-computed-fields","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voorhoede%2Fdatocms-plugin-computed-fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voorhoede%2Fdatocms-plugin-computed-fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voorhoede%2Fdatocms-plugin-computed-fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voorhoede%2Fdatocms-plugin-computed-fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voorhoede","download_url":"https://codeload.github.com/voorhoede/datocms-plugin-computed-fields/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voorhoede%2Fdatocms-plugin-computed-fields/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28751816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T10:25:12.305Z","status":"ssl_error","status_checked_at":"2026-01-25T10:25:11.933Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computed-fields","datocms-plugin","open-source"],"created_at":"2026-01-25T10:34:44.546Z","updated_at":"2026-01-25T10:34:44.613Z","avatar_url":"https://github.com/voorhoede.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DatoCMS plugin: Computed fields\n\n**This DatoCMS plugin allows to compute and define a field value based on other fields. This allows pretty “preview” values in the CMS (used in model overviews and for linked models). And moves logic from clients to a central place: the API.**\n\n![](https://github.com/voorhoede/datocms-plugin-computed-fields/raw/main/docs/plugin.png)\n\n\u003e Used code:\n\u003e ```JS\n\u003e const newDate = new Date(date)\n\u003e return `${title} | ${newDate.getFullYear()}`\n\u003e ```\n\n## Features\n\n* Return specified values\n* Use all javascript functionality\n* Get a model and an upload with an ID\n* Have access to all fields on the page\n\n## Configuration\n\nFirst add this plugin via DatoCMS Settings \u003e Plugins \u003e Add (`/admin/plugins/new`).\n\n### Plugin settings\n\nWhen adding the plugin you have to add a DatoCMS read only token in the general settings. This is necessary to be able to use two helper functions for returning uploads and models.\n\nAll code added in the plugin will be wrapped around an async function. This way you can use the two helper functions with an await.\n\nAlways return the value a field requires. For example:\n* For a string it should be a string.\n* For the JSON field it should be a JSON object.\n* For a boolean it should be `true` or `false`\n\nWhen you are not returning the value a field requires it will give a DatoCMS error.\n\n#### Show debug code editor\n\n\u003e Only show this editor when you want to have a sandbox to help you make an usefull function.\n\n![](https://github.com/voorhoede/datocms-plugin-computed-fields/raw/main/docs/plugin-debug-editor.png)\n\n**Only for testing purposes:**\nThe value in this editor will not be saved. You copy this value and add it to the \"Default function\" option of this plugin.\n\n#### Enter the default function\n\nThe value in this input will be wrapped around an async function. As soon as you add a return it will return that value.\n\nAll fields of the page you added will be automatically added as variable using the *field ID*.\n\nWhen you have added the field *Title*, in the function you can use the variable `title` which would have the value of this field.\n\n![](https://github.com/voorhoede/datocms-plugin-computed-fields/raw/main/docs/plugin-default-function.png)\n\n#### Hide field\n\nThis will hide the field, but will not hide the title. To hide the title you could use a hidden character which will make it look like the field is hidden. Like this Unicode character: `‎` (U+200E)\n\n### Plugin helper functions\n\n`getModel(modelId)`, `getUpload(uploadId)` and `getFieldValue(formValues, fieldPath)` are functions to use in the plugin. When you have added the DatoCMS readonly token in the general settings of the plugin, you can use these two functions.\n\nFor example: When there is an `uploadId` you can use this function to get all data for this upload.\n```js\nconst upload = await getUpload(uploadId)\nreturn upload.title\n```\n\nFor example: When there is an `modelId` you can use this function to get all data for this model.\n```js\nconst model = await getModel(modelId)\nreturn model.title\n```\n\nFor example: To get the value of a field you can use the datoCmsPlugin variable.\n```js\nconst fieldValue = getFieldValue(datoCmsPlugin.formValues, datoCmsPlugin.fieldPath)\nreturn fieldValue\n```\n\n### Reserved words\n\n#### Changed fields (changedField)\n\nWhen you change a field on the DatoCMS page there will be a variable available with the name of the field that changed.\nThe variable `changedField` can be used throughout the code.\n\nUsing `console.log(changedField)` will log the value of the field that has changed only if you use that field in your code.\n\nWhen you change a field and the id of the field is not used in your code, the code will not be executed.\n\n#### Locale (locale)\n\n`locale` will return the current locale you are working with. If localization is turned on it will dynamically return the correct locale.\n\nFor example: You can get a title which is translated\n```js\nreturn title[locale]\n```\n\n#### DatoCMS Plugin (datoCmsPlugin)\n\n`datoCmsPlugin` will return the whole plugin context. In the [documentation](https://www.datocms.com/docs/plugin-sdk) you can see what properties and methods are exposed. The `datoCmsPlugin` variable is `ctx` of a field extension with the declared type: [RenderFieldExtensionCtx](https://github.com/datocms/plugins-sdk/blob/19af57b61bd763cdb9c3d4aa945408b577602cc0/packages/sdk/src/connect.ts#L72).\n\nFor example: The `datoCmsPlugin` can give you the id of the model your are editing\n```js\nreturn datoCmsPlugin.itemId\n```\n\n#### This block (thisBlock)\n\nWhen using the plugin inside a modular content block it's difficult to get the data fields from the item you have added. For this you can use the `thisBlock` variable which returns an object of the fields inside that block. From this object you can get all the fields and destructure that object to get the correct data.\n\nFor example: The `thisBlock` can give you data of the current block you are working in\n```js\nreturn thisBlock.title\n```\n\n## Plugin Fields\n\nAll fields in this list can be used together with the computed fields plugin. The checked values are designed to show data in a user friendly manner.\n\n- [x] JSON (json)\n- [x] Text (text)\n- [x] Boolean (boolean)\n- [x] Float (float)\n- [x] Integer (integer)\n- [x] String (string)\n- [ ] Structured text (structured_text)\n- [ ] Multiple links (links)\n- [ ] Single link (link)\n- [ ] Date (date)\n- [ ] Date-time (date_time)\n- [ ] Video (video)\n- [ ] Color (color)\n- [ ] Seo (seo)\n- [ ] Geolocation (lat_lon)\n\n## Contributing\n\nSee [contributing.md](https://github.com/voorhoede/datocms-plugin-computed-fields/blob/main/contributing.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoorhoede%2Fdatocms-plugin-computed-fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoorhoede%2Fdatocms-plugin-computed-fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoorhoede%2Fdatocms-plugin-computed-fields/lists"}