Bug in FilterFieldV3 function (SharePoint core.js)

 

In SharePoint List Views, when you want to display the Filter Choices, you can add a parameter to URL : &Filter=1 

or use SP Designer to add a parameter for XSLTListViewWebPart: Name: Filter; Value: 1

This works fine with Field Name that do not contain special characters or space.

But with the Field Name contains special characters or space, the Reset Filter does not work fine:

1.

image

2.  

 image

The Views did not reset data for this.

The problem come from: FilterFieldV3 function (in core.js)

On this function, via call to CanonicalizeUrlEncodingCase, the Url will be changed the FilterField from f –> F

Example: "Roll%5fx0020%5fOut%5fx0020%5fPhase" –> "Roll%5Fx0020%5FOut%5Fx0020%5FPhase"

Default%20Filter.aspx?View={37BE24A2-9C85-4C92-A655-EC7B10CAD8D4}&FilterField1=Roll%5fx0020%5fOut%5fx0020%5fPhase&FilterValue1=Phase%202&Filter=1

->

Default%20Filter.aspx?View={37BE24A2-9C85-4C92-A655-EC7B10CAD8D4}&FilterField1=Roll%5Fx0020%5FOut%5Fx0020%5FPhase&FilterValue1=Phase%202&Filter=1

and in the:  arrayField=strDocUrl.match("FilterField([0-9]+)="+fieldName+"&");
will return null because the strDocUrl is “Default%20Filter.aspx?View={37BE24A2-9C85-4C92-A655-EC7B10CAD8D4}&FilterField1=Roll%5Fx0020%5FOut%5Fx0020%5FPhase&FilterValue1=Phase%202&Filter=1”

and the fieldName is Roll%5fx0020%5fOut%5fx0020%5fPhase

You can fix this problem by changing in core.js (not recommend)

arrayField=strDocUrl.match("FilterField([0-9]+)="+fieldName+"&");

to

arrayField=strDocUrl.match(new RegExp("FilterField([0-9]+)="+fieldName+"&",”i”));

 

Or override the  FilterFieldV3 by adding a new WebPart (Content Editor or HTML Form…). Make be sure you update the way site load core.js (Ref: http://trungpv.blogspot.com/2011/06/sharepoint-javascript-on-demand-spsod.html)

   <SharePoint:ScriptLink language="javascript" name="core.js" OnDemand="false" runat="server"/>

This is a SharePoint bug, Microsoft should update the core.js

Comments

Popular posts from this blog

Referencing Javascript Files with SharePoint 2010 Custom Actions using SciptSrc

Configure Excel Services data access by using external data connection

Uninstall SQL Server Embedded