[fieldFormat/contentType] fix a bug converting null to html

This commit is contained in:
Spencer Alger 2015-05-05 10:44:42 -07:00
parent 5924d844e6
commit 5e9559af96

View file

@ -6,30 +6,29 @@ define(function (require) {
var types = {
html: function (format, convert) {
return function recurse(value, field, hit) {
var type = typeof value;
if (type === 'object' && typeof value.map === 'function') {
if (value.$$_formattedField) return value.$$_formattedField;
var subVals = value.map(recurse);
var useMultiLine = subVals.some(function (sub) {
return sub.indexOf('\n') > -1;
});
return value.$$_formattedField = subVals.join(',' + (useMultiLine ? '\n' : ' '));
if (!value || typeof value.map !== 'function') {
return convert.call(format, value, field, hit);
}
return convert.call(format, value, field, hit);
// format a list of values. Lists of values will have their formatted values cached
if (value.$$_formattedField) return value.$$_formattedField;
var subVals = value.map(recurse);
var useMultiLine = subVals.some(function (sub) {
return sub.indexOf('\n') > -1;
});
return value.$$_formattedField = subVals.join(',' + (useMultiLine ? '\n' : ' '));
};
},
text: function (format, convert) {
return function recurse(value) {
if (value && typeof value.map === 'function') {
return angular.toJson(value.map(recurse), true);
if (!value || typeof value.map !== 'function') {
return convert.call(format, value);
}
return convert.call(format, value);
// format a list of values. In text contexts we just use JSON encoding
return angular.toJson(value.map(recurse), true);
};
}
};