1
votes

Can I somehow add words to the Summernote's dictionary that I get from the server? By default, Summernote supports an option called "hint" and you can predefine a dictionary for hint words in "words" like here:

$(".hint2basic").summernote({
height: 100,
toolbar: false,
placeholder: 'type with apple, orange, watermelon and lemon',
hint: {
 words: ['apple', 'orange', 'watermelon', 'lemon'],
 match: /\b(\w{1,})$/,
 search: function (keyword, callback) {
  callback($.grep(this.words, function (item) {
    return item.indexOf(keyword) === 0;
  }));
 }
}
});

But what if I want to add some other words that I got from the server:

$.ajax({
            beforeSend: function(request) {
            request.setRequestHeader("Accept", "application/ld+json");},
            url:'MY URL', 
            type:'POST',
            data:JSON.stringify(jsonld),
            success: function(response)
            {
                //here must be something, e.g.
                var arrayWithWords = response;
            }
      });

In "arrayWithWords" I have now a string, e.g. "car", "house", "bag".

What I should do now to add this "arrayWithWords" into Summernote's "words" or just replace the "words" value with the value of "arrayWithWords"? The main problem is that you must predefine a dictionary for hint words in Summernote BEFORE a user can use Summernote and I don't see any way to update "words".

1

1 Answers

2
votes

I just stumbled on this question while looking for something else so, sorry for the necro-post here. If you haven't already figured this out, you can just use your arrayWithWords variable in the callback function for the hint search, rather than using the word list defined at initialization. Any time the search runs, it will use the current value of arrayWithWords.

$(".hint2basic").summernote({
height: 100,
toolbar: false,
placeholder: 'type with apple, orange, watermelon and lemon',
hint: {
 match: /\b(\w{1,})$/,
 search: function (keyword, callback) {
  callback($.grep(arrayWithWords, function (item) {
    return item.indexOf(keyword) === 0;
  }));
 }
}
});