0

Basically I'm creating an object using modal with form and I'm sending the data using socket.io. I want to update the information displayed when the new item is added after the form submission without refreshing the page.

Adding function:

  //TODO: Make validations for the cluster using Node-ORM2
  add: function(m, db, socket) {
    db.models.cluster.createAsync({ name : m.name, shop_id : m.shop, display_id : m.display}).then(function(result) {
      socket.emit('message', {
        success : true,
        msg : 'Cluster successfuly added to the database.'
      })
    })
  }

EJS Code:

 <div class="row">
  <% clusters.forEach(function(cluster) { %>
    <div class="col-sm-12 col-md-3">
      <div class="card">
        <div class="card-header bg-light">
          <%= cluster.name %>
        </div>
        <div class="card-body">
          <ul id="cluster" data-name="<%= cluster.id %>" class="list-group">
            <% if(cluster.devices.length == 0) { %>
              <li class="list-group-item ignore">No active devices in this cluster.</li>
              <% } %>  
              <% for(var i = 0; i < cluster.devices.length; i++) { %>
                <li data-id="<%= cluster.devices[i].id %>" class="list-group-item"><%= cluster.devices[i].name %></li>
                <% } %>
              </ul>
            </div>
          </div>
        </div>
        <% }) %>
      </div>
GhoSTBG
  • 187
  • 1
  • 1
  • 11
  • You might want to check the client side rendering option with ejs. There's a similar question which you can check https://stackoverflow.com/questions/41001619/client-side-and-server-side-rendering-of-ejs-template – Swati Anand Jun 24 '18 at 17:11
  • @SwatiAnand I'm using EJS on the server side not in the front-end –  GhoSTBG Jun 27 '18 at 20:37
  • Then you'd need to send the EJS-rendered response string back through the socket and the client would inject it into the document somewhere. – ggorlen May 31 '22 at 22:49

0 Answers0