Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I update the rendered HTML for a node, I don't care about export #172

Closed
ptrthomas opened this issue May 14, 2021 · 6 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@ptrthomas
Copy link

this is what I tried:

    var id = '1';
    var node = editor.drawflow.drawflow.Home.data[id];
    node.html = '<div>HELLO WORLD</div>';
    editor.updateNodeDataFromId(id, {});

I was hoping to update the HTML visible, but it doesn't work. This is read-only HTML and no input or textarea is involved, so df-name won't work. I know how to update the data, but here I want the HTML to "update".

my use case is there is a separate edit popup, and after closing that, I want the respective node to "redraw".

is there a way to get the HTML DOM reference of a node ? I can then set the innerHTML directly

any suggestions would be appreciated !

@SamuraiDante
Copy link

If I understand you correctly then this would be one way I think:
var t = document.querySelector(".drawflow-node[id='node-1'] .drawflow_content_node");

@jerosoler
Copy link
Owner

That you comment @SamuraiDante is correct.

@jerosoler jerosoler self-assigned this May 14, 2021
@jerosoler jerosoler added the question Further information is requested label May 14, 2021
@ptrthomas
Copy link
Author

@SamuraiDante thank you, that helps !

in case this helps anyone else, I found that editor.import(editor.export()) will also do what I wanted, which is to "apply" any changes made to the node html property.

let me know if that is an ok approach @jerosoler - and thank you very much for this awesome library !

@shubhambattoo
Copy link

@jerosoler I tried the following code to update the html inside the node, but when I try editor.export() I am getting the old HTML only, as I am using this with React so assuming library is ignoring this change? Or is this expected?

const el = document.querySelector(
  `.drawflow-node[id='node-1'] .drawflow_content_node`
);
el.innerHTML = `<div id="my-id" class="box"> New Inner Text </div>`;

@jerosoler
Copy link
Owner

Hello @shubhambattoo

You have to update the json as well.

editor.drawflow.drawflow.Home.data[5].html = "...."

View: #40

@shubhambattoo
Copy link

@jerosoler Yeah that worked. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants