Sharepoint - Custom Integer Column - Remove thousand separator in EditForm - sharepoint-2010

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>

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)

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.

Related

Odoo 10 - Custom module to replace mail templates

I want to write a custom module to replace mail templates.
Those templates are included in base Odoo addons, such as sale:
The sale.order template ìs provided by the file /sale/data/mail_template_data.xml
This template is as follows:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!--Email template -->
<record id="email_template_edi_sale" model="mail.template">
<field name="name">Sales Order - Send by Email</field>¬
...
</odoo>
As the custom module wants to replace this standard base template:
Can a record with the same id be provided by the custom module to replace this mail template?
What shall be writte in <data noupdate>?
What will happen if module sale is updated?
Odoo 10 community edition.
For replacing the Email Templates just add the addon name in-front of the template name followed by dot(.) and make sure that you delete the default email template from the front end. Then update your custom addon. This will replace the old template.
Example:
<record id="sale.email_template_edi_sale" model="mail.template">
<field name="name">Sales Quotation</field>
<field name="email_from">${(object.user_id.email and '%s <%s>' % (object.user_id.name, object.user_id.email) or '')|safe}</field>
<field name="subject">${object.company_id.name} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' })</field>
<field name="partner_to">${object.partner_invoice_id.id}</field>
....
....
</record>
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!--Email template -->
<record id="email_template_edi_sale" model="mail.template">
<field name="name">Sales Order - Send by Email</field>
...
</odoo>
Please add your code to
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<delete model="mail.template" search="
[('id','=',ref('sale.email_template_edi_sale'))]"/>
<!--Email template -->
<record id="sale.email_template_edi_sale" model="mail.template">
<field name="name">Sales Order - Send by Email</field>
...
</odoo>
This will delete the original mail template and add a new template with the same ID so that the odoo functionlity is not disturbed.
Don't delete original template, you will lose the original module field and somethings will stop to work. Instead change noupdate value in ir.model.data for your template.
To do this automatically on module update:
Modify model 'ir.model.data' and add an allow_update method, creating a ir_model_data.py in models folder (modify __init__.py to include new file):
from odoo import models, fields, api
class IrModelData(models.Model):
_inherit = 'ir.model.data'
#api.model
def allow_update(self, module, name, model):
self.search([('module', '=', module), ('name', '=', name), ('model', '=', model)])[0].noupdate = False
Add function call element to allow_update before your record update and pass the original module name, external_id and 'mail.template':
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<function model='ir.model.data' name='allow_update'>
<value>sale</value>
<value>email_template_edi_sale</value>
<value>mail.template</value>
</function>
<record id="sale.email_template_edi_sale" model="mail.template" >
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
% set doc_name = 'quotation' if object.state in ('draft', 'sent') else 'order'
Dear ${object.partner_id.name}

asp.net mvc4 clientside validation doesn't work

I have clientside validation enabled in my config and I'm also including the appropriate jquery files for validation, but every time I submit, the page posts to server without first doing clientside validation. I have pasted the markup generated in the source below. It seems to be generating the data- validation messages fine. Just somehow not triggering validation.
I'm using the BeginCollection library that's available on Nuget to build my dynamic form. Could that be a reason for my clientside validation for somehow not working?
<input class="text-box single-line valid" data-val="true"
data-val-number="The field DaysAbsent must be a number."
data-val-required="The DaysAbsent field is required."
id="students_471abdc8-b190-42da-9f72-ed30a1e33b10__DaysAbsent"
name="students[471abdc8-b190-42da-9f72-ed30a1e33b10].DaysAbsent"
type="text" value="0">
My web.config:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
_Layout.cshtml:
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/jqueryui")
#Scripts.Render("~/bundles/jqueryval")
#RenderSection("scripts", required: false)
BundleConfig.cs:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
You mentioned dynamic form, so if you are loading your inputs dynamically jquery.validate doesn't know they are there. You have to "refresh" your form validations to validate your new inputs.
After adding a new input, use this code to "refresh" the validations for your form:
$('form').removeData('validator');
$('form').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse($('form'));

Passing value from Default.aspx to App or Main page in silverlight3

I'm using silverlight3 and vb.net..I want to pass the value from Default.aspx to my App or Main page. I wrote the code in my default.aspx page which it is returning the local ip address of the client System, I would like that same address to be used in my silverlight pages.
VB code
Dim clientIPAddress = System.Net.Dns
.GetHostAddresses(strHostName).GetValue(0).ToString()
This clientIPAddress will get the local ip of the client which is like 192.168.1.12. Now i want this value to be passed to my main page.
Please any one help to pass this value from default.aspx to my main page.
Thanks
Your default.aspx page will have an <object> tag where the Silverlight plugin is loaded. You can added a <param name="initParams value="clientID=192.168.1.12"> so it looks something like:-
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/Silverlight3App.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams` value="clientID=192.168.1.12"`>
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
Except of course you wouldn't hardcode the IP address but you'd inject that with some VB.NET code (I don't do VB.NET).
The initParams parameter is a set of name=value pairs that are exposed in Silverlight as a IDictionary(Of String, String). You can get this dictionary from the Application Startup event arguments or from Application.Current.Host.InitParams.

Add Custom Webparts to Custom ASPX Page in SharePoint 2010

I am creating a custom aspx page to deploy to my SharePoint 2010 site.
Is it possible to have regions in my custom aspx page to allocate webparts to?
I am planning on creating some custom webparts and being able to move them around the page if needed would be a benefit for my aspx page.
Thanks.
Yes, use the standard WebPartZones with the sharepoint master pages (so you can add/configure the webparts)
<%# Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,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" %>
<%# Import Namespace="Microsoft.SharePoint" %>
<%# Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"></WebPartPages:WebPartZone>
</asp:Content>
If you dont have the sharepoint master page, or any master page, you could still have the zones, but it is going to be hard work setting up the webpart editing tools.

Apache Struts: Cannot retrieve ActionForward

I am trying to learn the Apache Struts framework and I have written a small application that does class enrollments but whenever I try and load up my application it just spits out the following exception:
javax.servlet.ServletException:
org.apache.jasper.JasperException:
javax.servlet.ServletException:
javax.servlet.jsp.JspException: Cannot create rewrite URL:
java.net.MalformedURLException: Cannot retrieve ActionForward named adminLogin
My index.jsp page looks like:
<%# taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<logic:redirect forward="showLogin"/>
The relevant parts of my struts-config.xml:
<global-forwards>
<forward name="showLogin" path="/showLogin.do" />
</global-forwards>
<action-mappings>
<action path="/showLogin" forward="/pages/choose.jsp" />
<action path="/adminLogin" forward="/pages/adminLogin.jsp" />
</action-mappings>
And finally the choose.jsp file:
<%# page import="javax.sql.*"%>
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<h1>Who are you?</h1>
<ul>
<li><html:link forward="adminLogin">Administrator</html:link></li>
<li><html:link forward="instructorLogin">Instructor</html:link></li>
<li><html:link forward="studentLogin">Student</html:link></li>
</ul>
I don't do Struts, so don't pin me on it, but the error seems to indicate that it is expecting a <forward name="adminLogin" /> somewhere in the config. You might want to have the same for the other two forwards.