Issue #2826💬 AnsweredOpened June 12, 2020by tonypartridge1 reactions

Custom Select list to text component?

快速解答by RJCAM1

Hi @tonypartridge here is an example code to achieve that You can see in the documentation for more details: https://grapesjs.com/docs/api/richtexteditor.html#add

Read full answer below ↓

Question

Hey Guys.

I've seen this before but now I cannot find it for the life of me. Basically on the text component we have the top bar: https://gyazo.com/754513edcebbb0566f18e384d3eba453

How can we insert a select list here for example:

Name Email Phone

which inserts: {{NAME}} {{EMAIL}} {{PHONE}}

It's a short code selector basically?

Answers (2)

RJCAMJune 12, 2020

Hi @tonypartridge here is an example code to achieve that

// An example with fontSize
rte.add('fontSize', {
  icon: `<select class="gjs-field">
        <option>1</option>
        <option>4</option>
        <option>7</option>
      </select>`,
    // Bind the 'result' on 'change' listener
  event: 'change',
  result: (rte, action) => rte.exec('fontSize', action.btn.firstChild.value),
  // Callback on any input change (mousedown, keydown, etc..)
  update: (rte, action) => {
    const value = rte.doc.queryCommandValue(action.name);
    if (value != 'false') { // value is a string
      action.btn.firstChild.value = value;
    }
   }
  })

You can see in the documentation for more details: https://grapesjs.com/docs/api/rich_text_editor.html#add

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.