isComponent is not returning trait
Question
Happy new year! I am having an issue with isComponent(). Here is my code:
const log = msg => console.log(msg);
comps.addType('selectReference', {
model: defaultModel.extend(
{
defaults: Object.assign({}, defaultModel.prototype.defaults, {
traits: [
{
changeProp: true,
type: 'select',
label: 'Reference ',
name: 'selectReference',
options: [] // start out empty and dynamically add to the array
}
]
}),
init: function() {
this.listenTo(this, 'change:selectReference', this.selectSlideSection);
},
selectSlideSection: function(e) {
const referencedSlideSectionId = e.changed['selectReference'];
const currentSlideSectionId = e.attributes['section-id'];
if (currentSlideSectionId != undefined && currentSlideSectionId != '') {
//send to ajax function that saves reference
saveSlideSectionReference(currentSlideSectionId, referencedSlideSectionId);
} else {
log(referencedSlideSectionId);
}
}
},
{
isComponent: function(el) {
const allowedToHaveReferences = ['type1', 'type2', 'type3'];
if (el.tagName == 'SECTION' && allowedToHaveReferences.indexOf(el.id) > -1) {
log('inside');
return { type: 'selectReference' };
}
}
}),
view: defaultType.view.extend({
render: function() {
defaultType.view.prototype.render.apply(this, arguments);
return this;
}
})
});
For some reason the only time the trait shows up in component settings is when I remove the if-statement completely from isComponent() and just return { type: 'selectReference' }. However, it becomes a trait of everything then. I have checked the el.tagName values and they are what I expect them to be. I have also made sure that I have the correct el.id values. I even checked the if-statement itself and it does indeed pass through the if-statement logs the output correctly. So, I am confused as to why the trait is not being returned. Please help. Thank you!
Answers (3)
Hi Nicholas, are you defining selectReference inside a plugin?
Hey Artur. Yes, it's inside of a plugin.
Tried your code here https://jsfiddle.net/vv7sch2u/ and seems to work properly
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1959
[Question] Edit innerHTML in a custom button
Hi All, I am trying to change the text in a button component, but I am not able to edit it. I added this type: I included the editable: tru...
Issue #1891
Can't create new button component
I'm having a hard time creating a new component for a <button> element. What am I missing? Is something bugged out here? Works fine if I ch...
Issue #845
Impossible to select Iframe
I've created a new type of component an general iframe, avoiding selecting the map, but when I try to select it in canvas so that the setti...
Issue #1962
[QUESTION] any other way to listen the traits option changes
HI, I added the code of listening to the changes made when the user selects the values in the dropdown. but I need to listen to the changes...
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.