Applying two different traits on same html tag but applies only one
Question
Hello @artf ,
If we need to initialize two traits on same HTML tag then it's possible or not?
Actually i define two different traits on same tag(on link/a tag).
Let me describe you in little bit brief.
Suppose i have one group of links which contains class is like not-drag-drop.
So, it's HTML code is like
<ul>
<li>
<a class="not-drag-drop" href="index.html">Home 1</a>
</li>
<li>
<a class="not-drag-drop" href="index2.html">Home 2</a>
</li>
<li>
<a class="not-drag-drop" href="index3.html">Home 3</a>
</li>
</ul>
So for above class not-drag-drop i want to add one traits like,
var domComponents = editor.DomComponents
var defaultType = domComponents.getType('default')
var dModel = defaultType.model;
var dView = defaultType.view;
domComponents.addType('not-drag-drop', {
model: dModel.extend(
{
defaults: Object.assign(
{},
dModel.prototype.defaults,
{
badgable: false,
copyable: false,
draggable: false,
droppable: false,
highlightable: false,
hoverable: false,
movable: false,
removable: false,
stylable: false,
propagate: ['badgable', 'droppable', 'highlightable']
}
)
},
{
isComponent: function(el) {
if (el.classList && el.classList.contains('not-drag-drop')) {
return {type: 'not-drag-drop'};
}
},
}
),
view: dView,
});
and for all the links i want to one more traits like,
var dType = editor.DomComponents.getType('link');
var dModel = dType.model;
var dView = dType.view;
editor.DomComponents.addType('link', {
model: dModel.extend({
defaults: Object.assign({}, dModel.prototype.defaults, {
traits: [
// strings are automatically converted to text types
// title,
{
type: 'select',
label: 'Target',
name: 'target',
options: [
{ value: '', name: 'This window' },
{ value: '_blank', name: 'New window' }
]
},
{
type: 'select',
label: 'Href',
name: 'href',
options: opts
}
],
}),
}, {
isComponent: function(el) {
if(el.tagName == 'A'){
return {type: 'link'};
}
},
}),
view: dView,
});
But when i click on link which contains class not-drag-drop then only traits apply not-drag-drop, not applies link trait, So, when i am going to change this link's href i am not getting the links dropdown just showing the input-box.
Can you please help me how can i figure it out this issue?
Answers (3)
The HTML code is already loaded in canvas? Did you try to execute your custom component definition via a plugin? Otherwise you're trying to see changes on already loaded components
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1296
Custom Rich Text Editor is not working
Hi @artf, I've just created a custom plugin of the RTE using different libraries like CKEditor 5, TinyMCE 4 or pell but all of them with th...
Issue #1696
Traits appear first time when draged custom component
Hi artf , i have created custom component and add traits for it , when dragging this component to editor and select it the setting traits w...
Issue #1369
[BUG] Class of a block doesn't always show in the classes section
Hello everyone, I have added many custom blocks and gave the same css class to all the images in those blocks. Let's call it for now 'image...
Issue #1888
[Question] Add custom html inside canvas
Hi there, I'm using grapes to export a custom json with all the information i need, instead of HTML and CSS. For doing that I'm parsing the...
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.