Grapesjs: [Question] Default values for traits field

Created on 22 Mar 2018  路  5Comments  路  Source: artf/grapesjs

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

outdated

Most helpful comment

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'
        }]

All 5 comments

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'
        }]

Thanks!

Hello @artf what about the select type ? It seems like we are not able to use a default value for select.. Keep in mind that options are dynamic ( I'm getting the options from a json that is being generate from back-end )so I'm not able to use something like that:

options: [
{value: 0, name: '1st option' },
{value: 1, name: '2nd option' }
]

code::
error

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crazyxhz picture crazyxhz  路  3Comments

tribulant picture tribulant  路  3Comments

krunal039 picture krunal039  路  3Comments

kawika-connell picture kawika-connell  路  3Comments

ionic666 picture ionic666  路  3Comments