Create one more key in JSON
Sorry I misunderstood your problem, so my previous comment was not relevant. To achieve your desire, you need create your own trait type (docs) and component type (docs). There is an easier way but it can not save all your custom data as an object to the data key. The JSON result would be like this: Sample code: You c...
Read full answer below ↓Question
{ "type": "text", "status": "hovered", "content": "Insert your text here", "attributes": { "id": "ixx2" }, "activeOnRender": 0, "open": false } In JSON I want add new key with object. Example data key this will have custom Traits. I want to add new object from where data can be fetch and populate the output. Can I do this? Below is sample object how I wanted. Can any one help me on this how can I achieve this. { "type": "text", "status": "hovered", "content": "Insert your text here", "attributes": { "id": "ixx2" }, "data":{ "url":"https://something.com", "refresh_rate":"10" }, "activeOnRender...
Answers (4)
Sorry I misunderstood your problem, so my previous comment was not relevant. To achieve your desire, you need create your own trait type (docs) and component type (docs). There is an easier way but it can not save all your custom data as an object to the data key. The JSON result would be like this...
I'm not sure if I get your problem.
But if you set any custom attributes to component model (except some preserve keys like components, styles, ...)
e.g: component.set('customTraits', yourCustomTraits);. It would be in JSON data.
I tried like this, but it is not working. I want to add data key and object in JSON, when user select form they can enter API url. Can you please check am I doing correctly?
Thanks for reporting this, @vijaycreatise. Great question about Create one more key in JSON. The recommended approach with GrapesJS is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event listener method Most operations can be ac...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3218
How to add new HTML element with inline styles?
I would like to add a new HTML element, with inline styles, around the rte.selection(). With the following example, the HTML is OK, but pro...
Issue #4416
Can't parse trait values using Template literals(String Interpolation)
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v103.0.5060.53 Reproducible demo li...
Issue #4001
Can not hold current unit when the first time input have Auto value
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? 96.0.4664.93 Reproducible demo link https:...
Issue #3496
FEAT: Mark Component as Dirty
What are you trying to add to GrapesJS? Component should be able to mark themselves as dirty, triggering the onbeforeunload warning message...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →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.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins — TinyMCE Inline Text Editor and Placeholder.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.