앰퍼샌드의 선택 필드의 선택은 HTML 인코딩이 나타납니다.
-
10-12-2019 - |
문제
Choice 필드를 만들었습니다. 선택한 선택 필드는 앰퍼샌드가 포함 된 다음 목록에 항목을 추가하고 선택 분야에서 앰퍼샌드를 사용하여 하나를 선택했습니다.
이제 앰퍼샌드가 HTML 인코딩 된 항목 (&
)이 나타납니다. 그러나 새로운 편집 양식 및 목록보기에서 앰퍼샌드로 올바르게 표시됩니다.
디스플레이 양식에 올바르게 표시되는 솔루션이 있습니까?
나는 2 개의 설치에서 그것을 시도했고, 이슈가 둘 다 존재했다. SharePoint 2013 Foundation을 사용하는 Windows Server 2008 R2에서 SQL Server 2012 및 SQL Server 2012에서 Windows Server 2012의 다른 Windows Server 2012에서는
Visual Studio에서 목록을 작성하고 SharePoint UI를 사용하여 결과가 두 접근 방식 모두에 대해 동일합니다.
해결책
On the Microsoft forums I got a suggestion to create a custom display form for the list. I don't really like that solution, so here is what I ended up doing:
I added a javascript file loaded to every page that overwrites the original Choice field rendering template for the DispForm. I realize that this is also not a great thing to do, but at least I only have to do it once.
The code in the file is:
// Fix for HTML encoded choice field value on display form
function registerChoiceFieldTemplateOverrides() {
var choiceFieldContextOverride = {};
choiceFieldContextOverride.Templates = {};
choiceFieldContextOverride.Templates.Fields = {
'Choice': {
// The important bit: Change the display form template to the one that doesn't encode the value again. The original function that was used is: SPField_FormDisplay_Default
'DisplayForm': window.SPField_FormDisplay_DefaultNoEncode,
},
};
window.SPClientTemplates.TemplateManager.RegisterTemplateOverrides(choiceFieldContextOverride);
}
ExecuteOrDelayUntilScriptLoaded(registerChoiceFieldTemplateOverrides, 'clientforms.js');