How to change extra dropdown for link change trait
Question
Hello @artf , I want to give one more functionality to user like user can change any link with default links drop down.

In above image i want to add one more dropdown for the default links.
If user will select the links from the drop-down then also need to change href of selected link and on other hand if user will type link into href input text-box(marked in above image) then also need to change the href of selected links.
How can i do this things can you please help me?
Answers (3)
Create a custom trait: https://grapesjs.com/docs/modules/Traits.html
Hello @artf
If i only want to do in change trait for href(<a ) tag then how can i change that?
I tried like,
var dType = domComps.getType('default');
var dModel = dType.model;
var dView = dType.view;
domComps.addType('a', {
model: dModel.extend({
defaults: Object.assign({}, dModel.prototype.defaults, {
traits: [
// strings are automatically converted to text types
{
type: 'select',
label: 'Href',
name: 'href',
options: [
{value: 'index.html', name: 'Home'},
{value: 'index2.html', name: 'Home2'},
{value: 'index3.html', name: 'Home3'},
{value: 'index4.html', name: 'Home4'},
]
}
],
}),
}, {
isComponent: function(el) {
if(el.tagName == 'a'){
return {type: 'a'};
}
},
}),
view: dView,
});```
But this is something like not works. Can you please help me at where i am doing wrong?
And one more question, how can i check the selected DOM element's type?
I guess it will use isComponent function. But i don't know how to use it and where?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1294
How to add category for default block manager?
@artf I want put all default blocks to category named "Basic". But I can't find any documents about it. I use editor.BlockManager.getAll()....
Issue #1398
GrapesJS translate
Hello @artf , Do I want to translate all functions into Hungarian, so that I can do it? Please give me examples of how to modify these text...
Issue #1926
[QUESTIONS] Edit Placeholder on keyup in Trait
How so that Placeholders can change when typing a word in the trait directly, current placeholders can change only when mouseover I have a...
Issue #457
Two Quick Questions
Hi @artf 1) I have my editor templates like this : I want to change the alignment and also add a back button to the corner left like this o...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.