Tushar
Tushar

Reputation: 126

why summernote not retrieving data into textarea for editing the text or for changes

I am using summernote rich text editor, and I want to edit my posted data(stored in DB). I am sending the value to the text area and inputs but not showing into the text area and showing into the input. kindly share some solutions and suggestions with me. any jquery and js function like this... here is rendered data to web page

 route.get('/edit/:id', async (req, res) =>{
    const id = req.params.id 
const article = await Article.findById(id)
res.render('editarticle',{article:article})
})

and here is ejs or HTML

<%- include('header'); -%>
<div class="container-9">
    <h2>Create Article Here</h2>
   <hr>
<form action="/create/blog" method='post'>
  <input type="text" name="title" id="" placeholder="Enter Title" value='<%=article.title%>'/>
  <input  type="text" name="description" id="dics" placeholder="Enter Description" value='<%=article.discription%>'/>
  <hr>

  <button id='btn-post' type="submit">Post</button>
  <textarea name='content' id="body" rows="10" value="<%=article.content%>" ></textarea>
</form>
</div>
<%- include('footer'); -%>

Upvotes: 0

Views: 2332

Answers (3)

ansa ps
ansa ps

Reputation: 1

pasteHTML will make duplicates on each call, use:

var value = $('#contentDumpDiv').html();

$('textarea#contentDumpDiv').summernote('code', value);

Upvotes: -1

Sayeed amin
Sayeed amin

Reputation: 49

@tushar Very useful !!

I use it on summer note as like

Put Content in a div, and set it display none

<div id="contentDumpDiv" style="display:none;">
<?php echo $post['content'] ?>
</div>

then use this javascript code

var value = $('#contentDumpDiv').html();
$('textarea#saContent').summernote('pasteHTML', value);

Upvotes: 0

Tushar
Tushar

Reputation: 126

I have solved this problem with help of one line of code. I have got the solution after 2 month

 var value = $('#value').val()
        console.log(value);
        $('textarea#body').summernote('pasteHTML', value);

if want to render the HTML for edit this will work, var value = $('#value').val() it just receiving the value (HTML) from the backend and $('textarea#body').summernote('pasteHTML', value); this line of code pesting the HTML into summernote editor.

Upvotes: 2

Related Questions