Issue #975✓ SolvedOpened March 22, 2018by rajanbharti4 reactions

Default values for traits field

Quick answerby artf3

Traits should read the default directly from their props/attributes, so in your case, it should be something like this:

Read full answer below ↓

Question

I have created component with certain traits. I am not able to assign default value to traits by passing values. It is coming as undefined for color type, blank for text field.

traits: [ {
          type: 'text',
          label: 'Placeholder',
          changeProp: 1,
          name: 'placeholder',
          value: 'Type your text here'
        },
        {
          type: 'color',
          label: 'Icon Color',
          changeProp: 1,
          name: 'iconColor',
          value: '#000000'
        }]

sett_gjs

Any changes in field is getting reflected in component

Answers (3)

👍 Most helpfulartfMarch 24, 2018

Traits should read the default directly from their props/attributes, so in your case, it should be something like this:

iconColor: '#000000',
placeholder: 'Type your text here',
traits: [ {
          type: 'text',
          label: 'Placeholder',
          changeProp: 1,
          name: 'placeholder'
        },
        {
          type: 'color',
          label: 'Icon Color',
          changeProp: 1,
          name: 'iconColor'
        }]
rajanbhartiSeptember 13, 2018

in your case, defaults should be like typeid: 0 pointing to the first element as default

rajanbhartiMarch 24, 2018

Thanks!

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.