Is there a simple way to use JS in scripting of a readTime value for a Schema field of type string where characters can be counted for vanilla/custom editor and then saved as a number field in Squidex. On every update of the content the formula reruns on the character/word count there by allowing a simple read time kind of functionality at Squidex Level.
The editor has word count at the footer section of editor.
Requirement:
Now our requirement is we need to update the word count from the custom editor to the input field which we have placed next to it which has been named as wordCount?
As per the example the word count of 2 needs to be updated in the input field wordCount .
Could you please help us to achieve the expected result through any JS scripts?
(i) wordCount Works but currently only for English (other languages field not getting updated) - please note I have created a localised field of type number called words in cloud app 'vannadevd'. Only the english field gets updated rest other languages showing empty
(ii) characterCount is not working
(iii) I think I might be making a mistake in the language codes may be
Analogy of e.g ctx.data.words.en (I am struggling with language codes in scripting apart from english language maybe that is why it is not working)
i) zh-TW should I use
ctx.data.words.zh-TW or ctx.data.words.tw
ii) zh-HK should I use
ctx.data.words.zh-HK or ctx.data.words.hk
Script Code
// Word Count in English
ctx.data.words.en = wordCount(html2Text(ctx.data.body.en));
replace();
// Word Count in HongKong Traditional Chinese (zh-HK)
ctx.data.words.hk = wordCount(html2Text(ctx.data.body.hk));
replace();
// Word Count in Taiwanese Traditional Chinese (zh-TW)
ctx.data.words.tw = wordCount(html2Text(ctx.data.body.tw));
replace();
//Character Count in English
ctx.data.chars.en = characterCount(html2Text(ctx.data.body.en));
replace();
Updated Script Code
// Word Count
ctx.data.words.en = wordCount(html2Text(ctx.data.body.en));
// Word Count
(ctx.data.words.zh) = wordCount(html2Text(ctx.data.body.zh));
// Word Count
(ctx.data.words.tw) = wordCount(html2Text(ctx.data.body.tw));
//Character Count
ctx.data.chars.en = characterCount(html2Text(ctx.data.body.en));
//Required to be called only once at the end of the script
replace();
Script Code
// Word Count (English)
ctx.data.words.en = wordCount(html2Text(ctx.data.body.en));
// Word Count (Taiwan)
ctx.data.words['zh-TW'] = wordCount(html2Text(ctx.data.body['zh-TW']));
// Word Count (HongKong)
ctx.data.words['zh-HK'] = wordCount(html2Text(ctx.data.body['zh-HK']));
// Word Count (China)
ctx.data.words['zh-CN'] = wordCount(html2Text(ctx.data.body['zh-CN']));
//Character Count (English)
ctx.data.chars.en = characterCount(html2Text(ctx.data.body.en));
// Character Count (Taiwan)
ctx.data.chars['zh-TW'] = characterCount(html2Text(ctx.data.body['zh-TW']));
// Character Count (HongKong)
ctx.data.chars['zh-HK'] = characterCount(html2Text(ctx.data.body['zh-HK']));
// Character Count (China)
ctx.data.chars['zh-CN'] = characterCount(html2Text(ctx.data.body['zh-CN']));
//Required to be called only once at the end of the script
replace();
@Sebastian
I have highlighted the mismatch in Tiny Editor’s word count vs our word count function(Previous screenshot). Plus character count also does not match. I am trying to guess what is the best way to count