Issue #1222Opened June 20, 2018by laziest-coder0 reactions

[Question] Adding new feature for BlockManager

Question

I want to use grapes.js to create a website constructor for clients and when they show the design it should show the price of constructed website according to how many elements are used. What I am struggling in is that I can not create variable called "Price" and when from Blockmanager something is dragged and dropped that variable "Price" should change.

Which line of code should I change to add "price" variable for every separate objects of Blockmanager and when object is dropped to specified place variable "price" changed?

Thanks in advance ! Hope that this kind of feature will help others too.

Answers (2)

artfJune 24, 20180 reactions

Currently, you should try with something like this

editor.BlockManager.add('your-block', {
	label: 'Your block',
	// ...
	content: { // your component
		price: 123,
		// ...
	}
});

editor.on('canvas:drop', (dr, component) => {
	const price = component.get('price');
	...
})

BTW I'd like to re-enable block specific events, so probably with the next release the process will be more concise

editor.BlockManager.add('your-block', {
	label: 'Your block',
	price: 123, // Add stuff to the block, not the component
	// ...
});

editor.on('block:drag:stop', (component, blockModel) => {
	const price = blockModel.get('price');
	...
})
lock[bot]September 17, 20190 reactions

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.