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

Any other way to listen the traits option changes

快速解答by artf

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

Read full answer below ↓

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, 2019

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, 2020

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.