Custom Select list to text component?
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)
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
@tonypartridge probably you're referring to this https://github.com/artf/grapesjs/issues/481#issuecomment-342282125
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5378
Uncaught TypeError: Cannot read properties of undefined (reading 'Canvas') while dragging a component in Layer Manager Panel
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v116.0.5845.97 Reproducible demo li...
Issue #3231
how to change gjs-ckeditor-format component
hi guys, we all know that gjs-ckeditor-plugin working with [data-gjs-type]="text" components. I wanna know , could we change this option? I...
Issue #2027
[QUESTIONS] How to add traits dynamically based on the dropdown selection
Hi @artf , I have a custom component with custom traits. When I select the option from the dropdown, more fields needs to be added based on...
Issue #5199
Changes in component's attributes being reproduced in all the instances instead of just one
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v114 Reproducible demo link https:/...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins β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.
Tutorial
Building an AI-Assisted Document Engine with Next.js, GrapesJS, and the AI SDK
Transform your static template editor into an intelligent, generative design workspace with Vercel AI SDK, AI Elements and Next.js.
Tutorial
Ship to Production Faster: Whatβs New in GrapesJS Shadcn
Supercharge your page builder! GrapesJS Shadcn adds live drag previews, rich text / commands, dynamic data, and canvas presets to ship to prod faster.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.