SharePoint的Stratus表单。单击提交按钮后比较输入

时间:2020-03-30 19:29:00

标签: javascript html forms sharepoint

我从Stratus表单中获得了这个用于SharePoint的出色表单,以便在SharePoint 2013上实现它。我可以使用它,但是想添加额外的验证,它无法识别或其他不起作用,因为当我单击提交时,即使没有匹配的输入,表单也会提交。以下是代码段。我不确定如何在输入和总和中添加适当的验证。

function CompareInputhpurs(){
   var inputTotalHours = document.getElementById("totalHours").value;
   var sumTotalhours = document.getElementById('Total');

   var comfirm = false;
   if(inputTotalHours===sumTotalhours){
	comfirm=true;
   } else {
	alert("Total hours worked does not match.Please input correct total hours.");
	comfirm =false;
	  }
}
	 
function SubmitForm(){
				
 //When the form is submitted store it to the specified list
 //also pass as in the x and y offset of error messages for elements
 //this allows you to change their location in reference to the form field
 $("#timesheetDiv").StratusFormsSubmit({
     listName: "DailySummary",
     errorOffsetTop: 0,
     errorOffsetLeft: 5,
     completefunc: function(id) { 
	    CompareInputhpurs();
	    alert("Save was successful. ID = " + id);
	   //window.location = window.location.pathname + "?formID=" + id; 
     }		
  });
}
<td>          
   <label class="thisLabel" for="time" >Total hours worked:</label>
   <input listFieldName="TotalHours" id="totalHours" class="inputClassSmall" validate="validNumber"/>        
</td>      
<div class="rTableRow">
   <div class="rTableCell"></div>
   <div class="rTableCell"></div>
   <div class="rTableCell"><label id="sumHours" class="thisLabel">Total hrs:</label><p id="Total"></p></div>	
</div>	
<input class="buttonClass" type="button" onclick="SubmitForm();" value="Add/Update Time Entry" />	

1 个答案:

答案 0 :(得分:0)

如果要进行客户端验证,应在StratusFormsSubmit之前调用CompareInputhpurs。

function SubmitForm(){
 CompareInputhpurs();               
 //When the form is submitted store it to the specified list
 //also pass as in the x and y offset of error messages for elements
 //this allows you to change their location in reference to the form field
 $("#timesheetDiv").StratusFormsSubmit({
     listName: "DailySummary",
     errorOffsetTop: 0,
     errorOffsetLeft: 5,
     completefunc: function(id) {       
        alert("Save was successful. ID = " + id);
       //window.location = window.location.pathname + "?formID=" + id; 
     }      
  });
}