Issue #731💬 AnsweredOpened January 9, 2018by ryandeba1 reactions

Traits of type "color" do not work

快速解答by artf1

Does the Trait object need a setValueFromInput method? This leads to the duplication of code but still think this will gonna work better moreover setTargetValue it's not actually a correct way because you have to update the model first (a listener will update the target later) The real problem is a bad design from the...

Read full answer below ↓

Question

Hi @artf,

I had previously mentioned in a pull request that traits of type color do not work. At the time I didn't have a need for them, but now I do so I'd like to look into fixing it if you haven't already started on it. The bug is in the InputColor object when it calls model.setValueFromInput - traits don't have that method so it throws an error. What do you think is the best way to fix this? Does the Trait object need a setValueFromInput method? Or should InputColor change so that it's smart enough to call different methods for a Trait vs a Property? Perhaps something else?

My initial (hacky) experimentation show that changing all of the model.setValueFromInput lines in InputColor to this gets it pretty close to working...not sure if this is the right path to go down or not though: model.setValueFromInput && model.setValueFromInput(cl, 0) || model.setTargetValue && model.setTargetValue(cl);

Answers (2)

artfJanuary 9, 2018

Does the Trait object need a setValueFromInput method?

This leads to the duplication of code but still think this will gonna work better

// in Trait.js
setValueFromInput(value, final = 1, opts = {}) {
	const toSet = { value };
    this.set(toSet, { ...opts, avoidStore: 1});
	
	// Have to trigger the change
	if (final) {
      this.set('value', '', opts);
      this.set(toSet, opts);
    }
  },

moreover setTargetValue it's not actually a correct way because you have to update the model first (a listener will update the target later)

The real problem is a bad design from the start. To be correct I should have inside 'abstract/ui' an InputModel and its InputView (same for other types of input), then using them inside traits and styles. Basically, the structure has to be closer to what is done with properties inside style manager but there is a little bit more work to do -.-

lock[bot]September 18, 2019

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.

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.