-1

In my project I have a form for messages the user can send to me, when the validation fail I need to display the errors for him, but the errors the I get from the backend is an object of arrays and I extracted the values and concatenated it in one string by this

    let errors = Object.values(data);
    let errorsMarkup = ""

    for (let i = 0; i < errors.length; i++) {
      errorsMarkup += `${errors[i]}`;
    }

now the string will be sentences that shows the errors separated by dots, I need it to be separated by break lines to show the user the errors one by line so I made this

    errorsMarkup = errorsMarkup.replace(/\./g,'<br>');

and I call the sweet alert to show the errorsMarkup

    Swal.fire({
      icon: 'error',
      title: 'Oops...',
      text: errorsMarkup
    });

but this is what I get

The Output

Osama Amr
  • 149
  • 1
  • 2
  • 13

2 Answers2

1

Use html property to pass HTML

Swal.fire({
  icon: 'error',
  title: 'Oops...',
  text: '',
  html: errorsMarkup
});
navnath
  • 3,548
  • 1
  • 11
  • 19
1

Try replacing text with html:

Swal.fire({
  icon: 'error',
  title: 'Oops...',
  html: errorsMarkup
});

You can refer to the official docs for help: https://sweetalert2.github.io/#usage

panchamk
  • 9
  • 5