I'm building a SharePoint SPFx using react.
In one of my components I want to have a comment section. Where a user can write a comment and then submit it to my Multiple lines of text
field called comments
. I currently have Append Changes to Existing Text
set to `Yes.
Below I have a textarea
to allow users to type a comment and then on submit I'm sending that comment to the comment field. However when someone submits another comment will this erase previous comments?
//Area to add comment
<textarea
value={this.state.Comments}
onChange={this.handleChangeComments}
rows={10}
required
/>
<button onClick={this.submitComment.bind(this)}>Submit</button>
//Function to submit comment
submitComment(event) {
event.preventDefault();
pnp.sp.web.lists.getByTitle("Requests").items.getById(120).update({
Comments: this.state.Comments,
}).then(i => {
console.log(i);
});
}
On another component I will make a call to display the comments and want it to look something similar to this:
<h4>Comments Below</h4>
<div>
<p>First comment here</p>
<p>07/12/2020 (get the date of submission I have a get_date function)</p>
</div>
<div>
<p>Second comment here that was left</p>
<p>07/10/2020</p>
</div>
<div>
<p>Another comment here</p>
<p>06/8/2020</p>
</div>
So I want that field to continue to hold all comments submitted and a way to loop
through each one. For comments I don't see there being any long comments or more than 10 comments added.
I was using this for reference: https://sharepointmaven.com/how-to-track-comments-with-append-changes-functionality-in-sharepoint-list/