Issue #709Opened January 4, 2018by NicholasGati0 reactions

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)

artfJanuary 4, 20180 reactions

Hi Nicholas, are you defining selectReference inside a plugin?

NicholasGatiJanuary 4, 20180 reactions

Hey Artur. Yes, it's inside of a plugin.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.