Hello, I am curious how to enable spellcheck on the document editor. I see from an older thread that it requires a serverside interaction but that was a whole project with a startup and etc. What is the simplest way I can implement a controller to handle spellcheck in one file?
HI Riley,
We will check and update further details shortly.
Regards,
Ajithamarlin E
Any updates?
//Please set your service url. <div> <SfDocumentEditorContainer ID="container" EnableSpellCheck="true"ServiceUrl="http://localhost:62869/api/documenteditor/"EnableToolbar="true"> <DocumentEditorContainerEvents></DocumentEditorContainerEvents> </SfDocumentEditorContainer> @code { SfDocumentEditorContainer container; public void onCreated() { var spellcheck = container.DocumentEditor.SpellChecker; // Document Editor provides multi-language spell check support. You can add as many languages (dictionaries) in the server-side and to use that language for spell checking in Document Editor, it must be matched with languageID you pass in the Document Editor. spellcheck.SetLanguageID(1046); spellcheck.SetRemoveUnderline(false); spellcheck.SetAllowSpellCheckAndSuggestion(true); } } |
-----------
If this post is helpful, please mark it as an answer so that other members can locate it more quickly.
I tried working with the repo but I am trying to narrow down what the minimum requirements are for spellcheck. In my blazor wasm project, I enabled the settings you posted on container.spellcheck on the OnLoad event. I see it posting to my controller in my blazor server project when I make changes. My spellcheck.json file is set to an empty list []. Here is my controller. What is it missing?
[Route("DocumentEditor")]
[ApiController]
public class DocumentEditorController : ControllerBase
{
static List
public DocumentEditorController()
{
Startup();
}
static string path = "C:\\Data\\MyApp";
static string jsonFileName = "spellcheck.json";
static string personalDictPath = "";
void Startup()
{
//check the spell check dictionary path environment variable value and assign default data folder
//if it is null.
//Set the default spellcheck.json file if the json filename is empty.
jsonFileName = Path.Combine(path, jsonFileName);
if (System.IO.File.Exists(jsonFileName))
{
string jsonImport = System.IO.File.ReadAllText(jsonFileName);
List>(jsonImport) ?? new();
spellDictCollection = new List
//construct the dictionary file path using customer provided path and dictionary name
foreach (var spellCheck in spellChecks)
{
spellDictCollection.Add(new DictionaryData(spellCheck.LanguadeID, Path.Combine(path, spellCheck.DictionaryPath), Path.Combine(path, spellCheck.AffixPath)));
personalDictPath = Path.Combine(path, spellCheck.PersonalDictPath);
}
}
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("SpellCheck")]
public string SpellCheck([FromBody] SpellCheckJsonData spellChecker)
{
try
{
SpellChecker spellCheck = new SpellChecker(spellDictCollection, personalDictPath);
spellCheck.GetSuggestions(spellChecker.LanguageID, spellChecker.TexttoCheck, spellChecker.CheckSpelling, spellChecker.CheckSuggestion, spellChecker.AddWord);
return Newtonsoft.Json.JsonConvert.SerializeObject(spellCheck);
}
catch
{
return "{\"SpellCollection\":[],\"HasSpellingError\":false,\"Suggestions\":null}";
}
}
[AcceptVerbs("Post")]
[HttpPost]
[EnableCors("AllowAllOrigins")]
[Route("SpellCheckByPage")]
public string SpellCheckByPage([FromBody] SpellCheckJsonData spellChecker)
{
try
{
SpellChecker spellCheck = new SpellChecker(spellDictCollection, personalDictPath);
spellCheck.CheckSpelling(spellChecker.LanguageID, spellChecker.TexttoCheck);
return Newtonsoft.Json.JsonConvert.SerializeObject(spellCheck);
}
catch
{
return "{\"SpellCollection\":[],\"HasSpellingError\":false,\"Suggestions\":null}";
}
}
public class SpellCheckJsonData
{
public int LanguageID { get; set; }
public string TexttoCheck { get; set; } = string.Empty;
public bool CheckSpelling { get; set; }
public bool CheckSuggestion { get; set; }
public bool AddWord { get; set; }
}
We will update details shortly.
Riley, have added the following configuration in your project?
In your JSON file, please add the below:
[
{
"LanguadeID": 1033,
"DictionaryPath": "en_US.dic",
"AffixPath": "en_US.aff",
"PersonalDictPath": "customDict.dic"
}
]