1

I am using QuillJs as an input field and quill-mention does not insert the selected mention in quill content.

  quillEditor = new Quill(editor, {
  formats: ['mention'],
  modules: {
    mention: {
      allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
      mentionDenotationChars: ['#'],
      source: function (searchTerm, renderList, mentionChar) {
        let values

        if (mentionChar === '#') {
          values = tags.map((i) => {
            return { value: i.name, id: i.name }
          })
        }

        if (searchTerm.length === 0) {
          renderList(values, searchTerm)
        } else {
          const matches = []
          for (let i = 0; i < values.length; i++)
            if (~values[i].value.toLowerCase().indexOf(searchTerm.toLowerCase())) matches.push(values[i])
          renderList(matches, searchTerm)
        }
      },
    },
  },
CodeCodeCodon
  • 385
  • 1
  • 4
  • 14

1 Answers1

0
mention: {

     allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
     mentionDenotationChars: ['{', '}', '#'],
     source: useCallback(
       (searchTerm: string, renderItem: any, mentionChar: string) => {
         let values;
         if (mentionChar === '{' || mentionChar === '}') {
           values = atValues;
         } else if (mentionChar === '#') {
           values = hashValues;
         }

         if (searchTerm.length === 0) {
           renderItem(values, searchTerm);
         } else if (values) {
           const matches = [];
           for (let i = 0; i < values.length; i += 1)
             if (
               values[i].value.toLowerCase().indexOf(searchTerm.toLowerCase())
             )
               matches.push(`{${values[i]}`);
           renderItem(matches, searchTerm);
         }
       },
       []
     ),
   },

use this

Kritarth Sharma
  • 356
  • 2
  • 7
  • This is not required. please refer: https://stackoverflow.com/questions/63649679/quill-mention-not-inserting-mention-value-in-quill-js-editor-content-using-re – Sahil Mar 20 '23 at 12:27