Vue.component("preview-field", {
template: '#preview-single-field-template',
props: [
'label',
'value',
'dataType',
'format',
],
mounted: function()
{
this.displayFormat = (this.format ? this.format : "");
},
destroyed: function()
{
},
data: function()
{
return {
displayFormat: "", // Refine the "format" so we don't mutate the prop.
item: {}
};
},
methods: {
getLabel: function()
{
return (this.label ? this.label : " ");
},
getValue: function()
{
// Return the value formatted.
// console.log("Display Format > " + this.displayFormat)
if (this.displayFormat == "url")
{
return "" + this.value + "";
}
if (this.displayFormat == "email")
{
return "" + this.value + "";
}
if (this.displayFormat == "phone")
{
return "" + this.value + "";
}
if (this.displayFormat == "multi-line")
{
var md = window.markdownit();
var result = md.render(this.value);
return result;
//return this.replaceLineBreaks(this.value);
}
if (this.displayFormat == "image")
{
return "
";
}
return (this.value ? this.value : " ");
},
replaceLineBreaks: function(value)
{
if (!value)
{
// Null or undefined or bad input
}
var output = "";
// Replace line-breaks with "\n"
//output = value.replace(/(?:\r\n|\r|\n)/g, '\\n');
output = value.replace(/(?:\r\n|\r|\n)/g, '
');
return output;
}
}
});