GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.37k stars 4.05k forks source link

Is it possible that I change value in traits that will directly reflected in component? #374

Closed HarshOB closed 7 years ago

HarshOB commented 7 years ago

Like If I created drop-down in traits and with a select value of dropdown I want to change the text that is present in that component without reloading or dragging that component again.

artf commented 7 years ago

This is how traits should work. When you update the value of the trait that change is reflected up to the component (example of input type in select component https://github.com/artf/grapesjs-plugin-forms/blob/master/src/components.js#L70-L78)

HarshOB commented 7 years ago

Let's say I made custom component and add that to grapes editor then I want to change body(You can say whole HTML/CSS) of that component using selected value in the drop-down from traits. Is it possible?

artf commented 7 years ago

Well, yeah, you can create traits with changeProp, then add a listener on that property change (inside Component's model) which triggers the appropriate action

HarshOB commented 7 years ago

I tried that. I write one function inside the model to change existing component.

// Edit
blockManager.get('productListing').set({
label: 'Updated simple block',
content: response
});

But this will not update that current component. When I drag same component again then It will reflect the change. What can I do to reflect the changes on the current window?

artf commented 7 years ago

I think you're confusing blocks with components, read first about Blocks and Components

HarshOB commented 7 years ago

image 1

What I want is when user select any templates from the drop-down(shown on right side) then that template will be loaded from template folder(shown on the left side) and on the fly, it will reflect on a window without reloading. Hope this will clarify what my requirement is.

artf commented 7 years ago

ok, what about editor.setComponents('<div>...</div>')?

blairpanek commented 6 years ago

@artf Well, yeah, you can create traits with changeProp, then add a listener on that property change (inside Component's model) which triggers the appropriate action What property changes when selecting something different for dropdown menus.

Created listener for name/value/selectedComponent/and component:update:content none worked

format was this.listenTo(this, 'change: x', this.myFunction)

myFunction(){ //do stuff }

lock[bot] commented 5 years ago

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.