Issue #975Opened March 22, 2018by rajanbharti4 reactions

[Question] Default values for traits field

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)

artfMarch 24, 20183 reactions

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, 20181 reactions

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

rajanbhartiMarch 24, 20180 reactions

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.