Preselect a trait select option
Hi @Chilli-B it would be better if you provide a live example of what you're trying to accomplish. BTW, if the trait is correctly created it should be synced with the component model, for example:
Read full answer below ↓Question
Hello, I'd like you to add to the options array of a select trait a third parameter next to 'name' and 'value', which is 'selected' in order to pre-select one of the trait options. In detail: I extended the header component by a select trait for all header types h1 through h6. Now I'd like to add something to the event function 'component:selected' so that when the component is clicked, the trait select for the header type is directly switching to the fitting option as far as a header tag is included (for example h2 tag is clicked => 2nd select option is pre-selected) I was wondering if there...
Answers (3)
Hi @Chilli-B it would be better if you provide a live example of what you're trying to accomplish. BTW, if the trait is correctly created it should be synced with the component model, for example:
Hi @artf , thanks for your reply. Below is how I created the trait by extending the text model for the header component. The problem is not the syncronization. The problem is, when I'm adding complete layouts to the canvas, which are including h2 or h3 tags (or any others), and I'm clicking on them...
The problem is not the synchronization. The problem is, when I'm adding complete layouts to the canvas, which are including h2 or h3 tags (or any others), and I'm clicking on them, the header type select in the settings (traits) always stays at "Headline 1", as this is the first option in the selec...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1714
auto select componet in RTE
When I add a link from RTE, it is not selected as the link component, I have to deselect the parent component that is the TEXT and select a...
Issue #544
Add select with optgroup
Hello @artf I have recently started using grapeJs and found it awesome. Can you please help me on How can I add dropdown(select) with optgr...
Issue #639
Re-render Component on Canvas when tagName has changed
I'm trying to build a basic Header component that lets you select H1 to H6 with a trait. But when an option is selected, the canvas doesn't...
Issue #1586
[Question] update Trait select option dynamically
I tried this to update trait selection. var updateTrait = function(id, name) { var typeTrait = model.get('traits').where({name: 'type'})[0]...
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.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.