question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] Reset trait on edit the content of a custom component

See original GitHub issue

Hi,

I have a custom component which content can be changed by switching trait select options, but also can be edited similar to the text component type when it is already rendered inside the canvas. Is there an easy way to reset the traits related attribute on edit of a component?

model: {
        defaults:  {
         type: 'tag',
          tagName: 'span',
          droppable: 0,
          editable: 1,
          textable: 1,
          traits: [{
            type: 'select',
            label: 'Custom type',
            name: 'customType',
            options: customTypeOptions,
          }],
        },
		toHTML() {
          return this.get('content');
        },

view: {
	events: {
            focus: 'resetTrait',
	},
	reseTrait() {
	}
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
inaLarcommented, Aug 24, 2019

@artf, regarding the “Select” I couldn’t manage to connect the change in the content and make it work on change of the trait in one flow and also to change it manually by editing it’s text/content. The manual change wasn’t syncing the trait, but I managed to make it work. A custom text component worked just fine.

As for the documentation from the last release, I am reading it right now and it looks very good, but I haven’t seen it when I posted the question.

It may be only me, but I learn by example, so more examples and use cases will be always a plus.

I understand that the product is open and I appreciate your effort. I hope that I will gain more knowledge and will be able to contribute with something in near future.

Cheers.

0reactions
artfcommented, Aug 24, 2019

Just one more thing - my trait is “Select”, so on marking the custom element in the canvas, the settings correspond to the current value of the components content. (this is working perfectly)

@inaLar I didn’t get the problem here

And maybe the documentation is more difficult for me to use.

Yes I agree, @artf could use a bit of work on the docs to provide a byte of better explanations and use cases.

In the last release, I rewrote the Trait documentation from scratch (and added new API for customization) by trying to cover all the possible needs requested so far by GrapesJS users (doing the same right now for Components). Obviously, I can’t cover all cases for all the people but if you have any suggestion are more than welcome

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Define Custom Traits on Grapes-js and How to ...
I am trying to do changing the position of the components by selecting the option on traits like if I Select traits to...
Read more >
Saving a custom component with new name resets the dialog ...
Question : I saved a custom component with new name and the dialog contents was reset, why? Answer: This happens because of the...
Read more >
Trait Manager - GrapesJS
Add Traits to Components · Built-in trait types. Text; Number; Checkbox; Select; Color; Button · Updating traits at run-time · Define new Trait...
Read more >
Quotas - Qualtrics
You can also automatically reset your quotas after a certain amount of time. ... This menu gives you the same options available in...
Read more >
Analytics.js 2.0 Source | Segment Documentation
By default, Analytics.js caches traits in the browser's ... Note: This must be an element, not a CSS selector. ... analytics.reset();.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found