1
votes

I created a new column definition in Sharepoint 2010 of type integer and with Commas set to false. A content type uses this column. When I create a list based on the content type, the "View Item" form will display the field correctly: 2010. The EditForm however will display it as 2,010: with a comma although commas is set to false.

This is a new integer field (not a number field converted to integer)

Any ideas how to display 2,010 as 2010 in the EditForm?

 <Field
  ID="{FF3B3FA8-AF33-4691-AD7E-1463DC024B99}"
  Name="studyYear"
  StaticName="studyYear"
  DisplayName="Study year"
  Title="Year"
  Description="Study year"
  Required="FALSE"
  Group="Custom Columns"
  Type="Integer"
  Commas="FALSE"
  Min="1900"
  Max="2300"
  MaxLength="4">
 </Field>
2

2 Answers

1
votes

I wanted to group list items by Year based the Created field, but needed to covert number to text to avoid 1000 separator (,)

So I created a calculated field with formula of =LEFT(YEAR(Created),1)&RIGHT(YEAR(Created),3)

0
votes

I have a custom field definition that I created in SharePoint 2010.

I basically followed the pattern set forth in this MS walkthrough. - then I changed their custom 'Field' example which inherits from 'SPFieldText' to instead inherit from SPFieldNumber, and my FieldControl inherits from NumberField.

Also, here's my field definition XML:

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
  <FieldType>
    <Field Name="TypeName">Wps</Field>
    <Field Name="SQLType">int</Field>
    <Field Name="InternalType">Integer</Field>
    <Field Name="ParentType">Number</Field>
    <Field Name="TypeDisplayName">Client WPS integer</Field>
    <Field Name="TypeShortDescription">Client WPS number</Field>
    <Field Name="UserCreatable">TRUE</Field>
    <Field Name="ShowOnListCreate">TRUE</Field>
    <Field Name="ShowOnSurveyCreate">TRUE</Field>
    <Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
    <Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
    <Field Name="FieldTypeClass">MyCompany.SharePoint.WpsField, $SharePoint.Project.AssemblyFullName$</Field>
  </FieldType>
</FieldTypes>

Like Karel, I had defined everything well enough that all commas were squashed.. except in the edit form.

I ended up adding some javascript to the custom .ascx that is part of my custom field definition.

 <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %> 
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="VB" %>
    <SharePoint:RenderingTemplate ID="WpsFieldControl" runat="server">
      <Template>
        <span id="commaField">
<asp:TextBox ID="TextField" runat="server"  Width="120px" />
        </span>
        <script type="text/javascript">// <![CDATA[
            var numFld = document.getElementById("commaField").childNodes[0];
            numFld.value = numFld.value.replace(",", "");
          // ]]>
        </script>
      </Template>
    </SharePoint:RenderingTemplate>

Note that I wrapped my ASP.NET TextBox in a simple SPAN with an ID that I could easily locate the field using getElementById in my JS. This was acceptable in my scenario, because the nature of our business would only ever require a single instance of my field type on a given SharePoint list record.

This seemed to solve everything for me! Maybe not the prettiest, but, I like that I don't have to clog up my list definitions with calculated columns.