0

I have a problem to load html into input field value. As the pictures.

A) When i save it:

enter image description here

B) When i load it:

enter image description here

C) The code used for create input field:

var templateField;
templateField = '<input type="text" id="' + fieldName + '" maxlength="' + args.maxlength + '" value="' + args.value + '"/>';
$controller.append(templateField);

Note: I can't append templateField first and after that do an innerHtml because i don't know what type of value will be (date, boolean, etc). This controller is used to create fields dynamic. I have this problem just when the type of value is String and the user put html values at the field.

j08691
  • 204,283
  • 31
  • 260
  • 272

1 Answers1

0

You need to escape the values before setting them:

function replaceStr(str) {
  return str
    .replace(/&/g, "&amp;")
    .replace(/"/g, "&quot;")
    .replace(/'/g, "&#39;")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;");

}

value="' + replaceStr(args.value) + '"

The single quote replacement is optional in this case.

Benny Lin
  • 536
  • 3
  • 8