Issue #1962Opened April 12, 2019by Ramkumar-Murugesan0 reactions

[QUESTION] any other way to listen the traits option changes

Question

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 in some other places in the code.

 comps.addType('input', {
      model: defaultModel.extend({
        defaults: Object.assign({}, defaultModel.prototype.defaults, {
          draggable: '*',
          droppable: false,
          traits: [
            { name: 'name', label: 'Name' },
            { name: 'placeholder', label: 'Placeholder' },
            {
              label: 'Type',
              type: 'select',
              name: 'mytype',
              changeProp: 1,
              options: [{ value: 'text', name: 'Text' },
              { value: 'email', name: 'Email' },
              { value: 'password', name: 'Password' },
              { value: 'number', name: 'Number' }]
            },
            { type: 'checkbox', name: 'required', label: 'Required' }
          ]
        }),
        init() {
          this.listenTo(this, 'change:mytype', this.mytype);
        },
        mytype() {
          alert('entity called');
        }

      },
        {
          isComponent: function (el) {
            console.log('ram iscomponent for radio tagname and ttype', el.tagName, '  ---  ', el);
            if (el.tagName === 'INPUT') {
              return {
                type: 'input'
              };
            }
          },
        }),

      // Define the View
      view: defaultType.view,
    });

In the above change working fine. but I need to listen to the changes in another place.

image

can anyone please help me

Answers (2)

artfApril 13, 20190 reactions

You can make use of a global listener editor.on('component:update:mytype', ...) or trigger some custom event inside the local method

...
		init() {
          this.listenTo(this, 'change:mytype', this.mytype);
        },
        mytype() {
          alert('entity called');
		  editor.trigger('YourEvent', { mytype: this.get('mytype') });
        }
...
lock[bot]April 15, 20200 reactions

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.

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.