Issue #2988💬 AnsweredOpened August 31, 2020by Abhisheknanda13444630 reactions

Trying to override of link trait

快速解答by Abhisheknanda1344463

It worked after placing a code in plugin.

Read full answer below ↓

Question

代码片段TEXT
Hi @artf I am trying to add new types of trait Below is my code.It's updating the values in code also but on reload link trait will set to default.
Here is my code
`editor.DomComponents.addType('link', {
  model: dModel.extend({
    defaults: Object.assign({}, dModel.prototype.defaults, {
      removable: false,
      traits: [
        // strings are automatically converted to text types
        {
          type: 'select',
          label: 'Pages',
          name: 'href',
          changeprop: 1,
          options: [
            {value: 'index.html', name: 'Home'},
            {value: 'index2.html', name: 'Home2'},
            {value: 'index3.html', name: 'Home3'},
            {value: 'index4.html', name: 'Home4'},
          ]
        },
				{
					type: 'href',
          label: 'Pages',
          name: 'href',
          changeprop: 1,
					category: { id: 'general',
          label: 'General', }
				},
				{
					type: 'select',
          label: 'Target',
          changeprop: 1,
          name: 'target',
          options: [
            {value: '', name: 'same'},
						{value: '_blank', name: 'new'},
          ]
        },
      ],
    }),
  }, {
    isComponent: function(el) {
      if(el.tagName == 'A'){
        return {type: 'link'};
      }
    },
  }),

  view: dView,
`});``
After reload when i click the existing one it shows the default one and when i drag new link element to the canvase in that case it shows me the custom one which i made above.
@artf  @ryandeba  Could you please help me on this.
Thanks

Answers (1)

Abhisheknanda1344463August 31, 2020

It worked after placing a code in 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...

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.