Overwrite sp.ui.listsearchbox.js to fix the SharePoint 2013 WAG issue

I conducted a WAG testing in SharePoint 2013 site using Google Chrome extension http://wave.webaim.org/extension/. The SharePoint site has some WAG issues and most of them are related to missing "Alt" attribute in the out of box image icon which created by SharePoint itself.

Most of them can be resolved by using jQuery to update the icon's HTML code directly. But I found one issue is exceptional that the inline search box icon within the List view document library WebPart can't be fixed by updating its HTML code directly. 

Bellow is the screenshot and icon's HTML code.



After I research the SharePoint Out Of box JavaScript, and I found out the "sp.ui.listsearchbox.js" composing the HTML code for the List view search box. 

"
  $1C_3: function(c) {
        var a = "<div id='{0}' class='ms-InlineSearch-Outline-Baseline ms-InlineSearch-Outline-Empty'><input id='{1}' title='{2}' class='ms-core-form-helper ms-InlineSearch-SearchBox-Baseline ms-InlineSearch-SearchBox-Empty' type='text' value='{3}' maxlength='2048'/><span id='{4}' class='{5}'><img id='{6}' class='{7}' src='{8}' title='{9}'/></span></div><div id='{10}' class='ms-InlineSearch-SearchProgress'><img src='{11}' title='{12}' style='vertical-align:middle;'/></div>"
          , b = String.format(a, SP.Utilities.HttpUtility.htmlEncode(this.get_$10_3()), SP.Utilities.HttpUtility.htmlEncode(this.get_$11_3()), SP.Utilities.HttpUtility.htmlEncode(this.$N_3), SP.Utilities.HttpUtility.htmlEncode(this.get_$5_3()), SP.Utilities.HttpUtility.htmlEncode(this.get_$15_3()), "ms-inlineSearch-searchImgSpanBase ms-inlineSearch-searchImgSpanStandard", SP.Utilities.HttpUtility.htmlEncode(this.get_$14_3()), "ms-inlineSearch-searchImg", GetThemedImageUrl("spcommon.png"), SP.Utilities.HttpUtility.htmlEncode(this.$R_3), SP.Utilities.HttpUtility.htmlEncode(this.get_$16_3()), SP.Utilities.HttpUtility.htmlEncode(this.$1_3.imagesPath + "loadingcirclests16.gif"), SP.Utilities.HttpUtility.htmlEncode(this.$17_3));
        c.innerHTML = b
    },
 "
At the end, I resolved above issue by overwriting the OOTB JavaScript as below function. It works fine to add "alt" attribute to the image icon's HTML code and the Google WAG extension reported no such error again!
//Overwrite List search box image's alt attribute - for WAG issue
ExecuteOrDelayUntilScriptLoaded(UpdateListSearchBox, 'sp.ui.listsearchbox.js');
function UpdateListSearchBox(){
Microsoft.SharePoint.Portal.ListSearchBox.prototype.$1C_3=function(c) {
   var a = "<div id='{0}' class='ms-InlineSearch-Outline-Baseline ms-InlineSearch-Outline-Empty'><input id='{1}' title='{2}' class='ms-core-form-helper ms-InlineSearch-SearchBox-Baseline ms-InlineSearch-SearchBox-Empty' type='text' value='{3}' maxlength='2048'/><span id='{4}' class='{5}'><img id='{6}' class='{7}' src='{8}' title='{9}' alt='{9}' /></span></div><div id='{10}' class='ms-InlineSearch-SearchProgress'><img src='{11}' title='{12}' style='vertical-align:middle;' alt='{12}' /></div>"
          , b = String.format(a, SP.Utilities.HttpUtility.htmlEncode(this.get_$10_3()), SP.Utilities.HttpUtility.htmlEncode(this.get_$11_3()), SP.Utilities.HttpUtility.htmlEncode(this.$N_3), SP.Utilities.HttpUtility.htmlEncode(this.get_$5_3()), SP.Utilities.HttpUtility.htmlEncode(this.get_$15_3()), "ms-inlineSearch-searchImgSpanBase ms-inlineSearch-searchImgSpanStandard", SP.Utilities.HttpUtility.htmlEncode(this.get_$14_3()), "ms-inlineSearch-searchImg", GetThemedImageUrl("spcommon.png"), SP.Utilities.HttpUtility.htmlEncode(this.$R_3), SP.Utilities.HttpUtility.htmlEncode(this.get_$16_3()), SP.Utilities.HttpUtility.htmlEncode(this.$1_3.imagesPath + "loadingcirclests16.gif"), SP.Utilities.HttpUtility.htmlEncode(this.$17_3));
        c.innerHTML = b
    }
}
This post is part of my project "Implement the Business Intelligence On Premises SharePoint 2013 Portal".
If you want to know more my experiences from the guide of above project, please sign up in here.

Comments

Popular posts from this blog

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

Effective LLM Prompting skills

Enable the Microsoft Power BI report file type (.pbix) in SharePoint Search