Hello! I'm a newbie and I've already searched all over the web and queries and I can't find a solution. I ask that if you are going to answer please keep in mind that I am a newbie so do not take terminology for granted. Here the question. I have a form that assigns validations to it, for example that the name field is not empty and that it must have at least 3 letters. I'm doing it with node.js and express-handlebars so I had to make a helper to be able to use it in view. The issue is that the helper works but it shows me the errors one attached to the other. step data code and info: Helper:
const Handlebars = require("handlebars");
Handlebars.registerHelper ("filtro", function (arrayErrors, name) {
if (arrayErrors !== undefined){
let listado= []
arrayErrors.forEach(campo=>{
if (campo.param===name){
listado+= campo.msg
console.log(listado);
}})
return listado
}
})
Here I apply it in the view:
<div class="row">
<div class="col-6">
<div class="input-group mb-3">
<img src="imagenes/iconos/nombre.png" width="45" height="45">
<input type="text" class="form-control col-6" placeholder="Nombre" aria-label="Nombre" id="nombreContacto" name="nombre" autofocus value="{{datosFormulario.nombre}}">
<span class="badge input-group text-uppercase fs-6 text-danger">
{{#filtro arrayErrors "nombre"}}
<p>{{msg}}</p>
</span>
{{/filtro}}
</div></div>
and finally a photo of the result that does not work for me:
Since you are writing
html
directly, you can use the tag<br />