magritton
3/30/2016 - 1:32 PM

SP JS SharePoint Form.txt

<table border="0">
		<tr>
		<td>
		Titlex:<br/>
		<span id="fTitle"></span>
		</td>
		<td>
		Single Linex:<br/>
		<span id="sLine"></span>
		</td>
		</tr>
		<tr>
		<td colspan="2">
		<span id="mLine"></span>
		</td>
		</tr>
		</table>
		<table>
		<tr>
		<td><span id="tChoice"></span>
		</td>
		<td><span id="sNumberField"></span></td>
		</tr>
		</table>


<!-- Start here -->
	<script src="http://sharepoint/SiteAssets/jquery-1.12.2.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			formControl();
			//SP.SOD.executeFunc('sp.js', 'SP.ClientContext', formControl);
		});//ends document ready function

	function formControl()
	{
		$('#titleRow').hide();//sharepoint row, add title
		$('#rSingleLine').hide();
		$('#multiLineRow').hide();
		$('#rChoice').hide();
		
		moveSPItems();
		$('#mLine').children().css('width','700px');
		$('#fTitle').children().css('width','200px');
	}
	function moveSPItems()
		{
			$('input[title="Title Required Field"]').appendTo($('#fTitle'));
			$('input[title="Single Line"]').appendTo($('#sLine'));
			$('textarea[title="Multiple lines"]').appendTo($('#mLine'));
			$('select[title="Choice Field"]').appendTo($('#tChoice'));
			$('input[title="A Number Field"]').appendTo($('#sNumberField'));
			
		}
		
	function PreSaveAction()
	{
		alert('test here!');
		return false;
	}
		</script>
	<!-- End here -->
<!--  
				<table>
					<tr>
						<td width="99%" class="ms-toolbar" nowrap="nowrap"><IMG SRC="/_layouts/images/blank.gif" width="1" height="18"/></td>
						<td class="ms-toolbar" nowrap="nowrap">
						-->
							<span id="spSave">
								<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton1"/>  
							</span>
							<!-- 
						</td>
						<td class="ms-separator">&#160;</td>
						<td class="ms-toolbar" nowrap="nowrap" align="right">
						-->
						<span id="spCancel">
							<SharePoint:GoBackButton runat="server" ControlMode="New" id="gobackbutton1"/>
						</span>
							<!--
						</td>
					</tr>
				</table>
				-->


<!-- 
				<table>
					<tr>
						<td width="99%" class="ms-toolbar" nowrap="nowrap"><IMG SRC="/_layouts/images/blank.gif" width="1" height="18"/></td>
						<td class="ms-toolbar" nowrap="nowrap">
							<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton2"/>
						</td>
						<td class="ms-separator">&#160;</td>
						<td class="ms-toolbar" nowrap="nowrap" align="right">
							<SharePoint:GoBackButton runat="server" ControlMode="New" id="gobackbutton2"/>
						</td>
					</tr>
				</table>
				 -->

	
<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->

					<span id="spTitle">
							<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="New" FieldName="Title" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}"/>
							<SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="Title" ControlMode="New"/>
					</span>
					<span id="spSingleLine">
							<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="Single_x0020_Line" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Single_x0020_Line')}"/>
							<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="Single_x0020_Line" ControlMode="New"/>
					</span>
					<span id="spMultipleLines">
							<SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="New" FieldName="Multiple_x0020_Lines" __designer:bind="{ddwrt:DataBind('i',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Multiple_x0020_Lines')}"/>
							<SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="Multiple_x0020_Lines" ControlMode="New"/>
					</span>
					<span id="spChoice">
						
							<SharePoint:FormField runat="server" id="ff4{$Pos}" ControlMode="New" FieldName="Choice" __designer:bind="{ddwrt:DataBind('i',concat('ff4',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Choice')}"/>
							<SharePoint:FieldDescription runat="server" id="ff4description{$Pos}" FieldName="Choice" ControlMode="New"/>
					</span>
					<span id="spNumberColumn">
							<SharePoint:FormField runat="server" id="ff5{$Pos}" ControlMode="New" FieldName="Number_x0020_Column" __designer:bind="{ddwrt:DataBind('i',concat('ff5',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Number_x0020_Column')}"/>
							<SharePoint:FieldDescription runat="server" id="ff5description{$Pos}" FieldName="Number_x0020_Column" ControlMode="New"/>
					</span>
					<span id="spCurrencyColumn">
							<SharePoint:FormField runat="server" id="ff6{$Pos}" ControlMode="New" FieldName="Currency_x0020_Column" __designer:bind="{ddwrt:DataBind('i',concat('ff6',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Currency_x0020_Column')}"/>
							<SharePoint:FieldDescription runat="server" id="ff6description{$Pos}" FieldName="Currency_x0020_Column" ControlMode="New"/>
					</span>
					<span id="spDateTimeField">
							<SharePoint:FormField runat="server" id="ff7{$Pos}" ControlMode="New" FieldName="Date_x0020_Time_x0020_Field" __designer:bind="{ddwrt:DataBind('i',concat('ff7',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Date_x0020_Time_x0020_Field')}"/>
							<SharePoint:FieldDescription runat="server" id="ff7description{$Pos}" FieldName="Date_x0020_Time_x0020_Field" ControlMode="New"/>
					</span>
					<span id="spYesNo">
							<SharePoint:FormField runat="server" id="ff8{$Pos}" ControlMode="New" FieldName="Yes_x0020_and_x0020_No" __designer:bind="{ddwrt:DataBind('i',concat('ff8',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Yes_x0020_and_x0020_No')}"/>
							<SharePoint:FieldDescription runat="server" id="ff8description{$Pos}" FieldName="Yes_x0020_and_x0020_No" ControlMode="New"/>
					</span>
					<span id="spHyperLinkerField">
							<SharePoint:FormField runat="server" id="ff9{$Pos}" ControlMode="New" FieldName="HyperLinker_x0020_Field" __designer:bind="{ddwrt:DataBind('i',concat('ff9',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@HyperLinker_x0020_Field')}"/>
							<SharePoint:FieldDescription runat="server" id="ff9description{$Pos}" FieldName="HyperLinker_x0020_Field" ControlMode="New"/>
					</span>
					<span id="spPictureField">
							<SharePoint:FormField runat="server" id="ff10{$Pos}" ControlMode="New" FieldName="Picture_x0020_Field" __designer:bind="{ddwrt:DataBind('i',concat('ff10',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Picture_x0020_Field')}"/>
							<SharePoint:FieldDescription runat="server" id="ff10description{$Pos}" FieldName="Picture_x0020_Field" ControlMode="New"/>
					</span>
					<span id="spPersonField">
							<SharePoint:FormField runat="server" id="ff11{$Pos}" ControlMode="New" FieldName="Person_x0020_Field" __designer:bind="{ddwrt:DataBind('i',concat('ff11',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Person_x0020_Field')}"/>
							<SharePoint:FieldDescription runat="server" id="ff11description{$Pos}" FieldName="Person_x0020_Field" ControlMode="New"/>
					</span>
					<span id="idAttachmentsRow">
							<SharePoint:FieldLabel ControlMode="New" FieldName="Attachments" runat="server"/>
							<SharePoint:FormField runat="server" id="AttachmentsField" ControlMode="New" FieldName="Attachments" __designer:bind="{ddwrt:DataBind('i','AttachmentsField','Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Attachments')}"/>
					</span>
<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->


<table border="0">
		<tr>
		<td>
		Title:<br/>
		<span id="sTitle"></span>
		</td>
		<td>
		Single Line:<br/>
		<span id="sLine"></span>
		</td>
		</tr>
		<tr>
		<td colspan="2">
		MultiLine:
		<span id="sMultiLine"></span>
		</td>
		</tr>
		</table>
		<table>
		<tr>
		<td>Choice: <span id="sChoice"></span></td>
		<td>Number Field: <span id="sNumberField"></span></td>
		<td>Currency Field: <span id="sCurrenyField"></span></td>
		</tr>
		<tr>
		<td> Date Time: <input type="text" id="datepicker"/><span id="sDateTime"></span></td>
		<td>Yes/No: <span id="sYesNo"></span></td>
		<td>Hyperlink: <span id="sHyperlink"></span></td>
		</tr>
		<tr>
		<td>Picture: <span id="sPicture"></span></td>
		<td>People Picker: <span id="sPerson"></span></td>
		<td>Attachments: <span id="sAttachmentsRow"></span></td>
		</tr>
		<tr>
		<td>Save: <span id="sSave"></span></td>
		<td></td>
		<td>Cancel: <span id="sCancel"></span></td>
		</tr>
		</table>


<script type="text/javascript">
	$(document).ready(function(){
			moveSPItems();
			//SP.SOD.executeFunc('sp.js', 'SP.ClientContext', formControl);
			//$('#spTitle').children().children().css('width','100px');
			setWidth('spTitle','200px');
			setCss('spSingleLine','background-color','blue');
			setCss('spSingleLine','color','white');
			$('#spSingleLine').children().children().val('Testing');
			$('#spPersonField div').text('administrator');
			$('#spPersonField [title="Check Names"]').click();
			var tDate = new Date();
			$('#spDateTimeField input').val((tDate.getMonth()+1)+'/' + (tDate.getDay()+1) + '/' + tDate.getFullYear());
			$('#spChoice select').val('Choice 2');
			$('#spNumberColumn input').val(16);
			$('#spYesNo input').prop('checked',true);
			$('#spHyperLinkerField input').eq(0).val('http://google.com');
			$('#spHyperLinkerField input').eq(1).val('Google search page');
			$('#spTitle input').val('Title Field');
			//var options = {year: "numeric", month: "short",day: "numeric"};
			//$('#spDateTimeField input').val(tDate.toDateString('en-us',options));
		});//ends document ready function
		
	function moveSPItems()
		{
			$('#spTitle').appendTo($('#sTitle'));
			$('#spSingleLine').appendTo($('#sLine'));
			$('#spMultipleLines').appendTo($('#sMultiLine'));
			$('#spChoice').appendTo($('#sChoice'));
			$('#spNumberColumn').appendTo($('#sNumberField'));
			$('#spCurrencyColumn').appendTo($('#sCurrenyField'));
			$('#spDateTimeField').appendTo($('#sDateTime'));
			$('#spYesNo').appendTo($('#sYesNo'));
			$('#spHyperLinkerField').appendTo($('#sHyperlink'));
			$('#spPictureField').appendTo($('#sPicture'));
			$('#spPersonField').appendTo($('#sPerson'));
			$('#spSave').appendTo($('#sSave'));
			$('#spCancel').appendTo($('#sCancel'));
			//$('[title="Browse"]').appendTo($('#sPerson'));
			//$('#idAttachmentsRow').appendTo($('#sAttachmentsRow'));
		}
		
		function setCss(itemID,css,v)
		{
			$('#' + itemID).children().children().css(css,v);
		}
		
		function setWidth(itemID,w)
		{
			$('#' + itemID).children().children().css('width',w);
		}
		
		function PreSaveAction()
	{
		alert($('#spPersonField').children().children().val());
		return false;
	}

</script>