Visualforce - 将 Javascript 用于必填字段



Team,

我正在使用Javascript在Salesforce Visualforce页面上工作,以验证必填字段 - 选项列表和文本字段。我尝试使用 htmlrequired = true,但这不起作用,因为我在我的视觉力量页面上有两个功能 - 保存链接和提交按钮。我希望用户在尝试提交并且必填字段为空/空时出现错误。下面是我的代码,但它不起作用。

<script>
	function submitOnClick(objSubmitBtn){
		var RevPL = document.getElementById('RevPL').value;
		if(RevPL == null || RevPL == ''){
			alert('Review needed.')
			return false;
		}
		var StatusPL = document.getElementById('StatusPL').value;
		if(StatusPL == null || AdhStatusPL == ''){
			alert('Status needed.')
		}
		
		var StatusPL = document.getElementById('Notes').value;
		if(StatusPL == null || AdhStatusPL == ''){
			alert('Please add notes.')
		}
		if(confirm('Are you sure you want to submit?')){
			objSubmitBtn.disabled = true;
			objSubmitBtn.value = 'Submitting... Please Wait';
			doSubmit();
		}
	}
</script>
<apex:form id="PRDetails"> 
	<table width="100%">
		<tr>
			<td width="50%">
				3. Review of documentation &nbsp;
					<b> <apex:outputText value="{!PR['Review__c']}" rendered="{!PR['Status__c']='Complete'}"/> </b>
						<apex:inputField value="{!PR['Review__c']}" rendered="{!PR['Status__c']!='Complete'}" id="RevPL" />
				
			</td>
		</tr> 
	</table>
	
	<br/>  
	
	<table width="100%">
		<tr>
			<td width="50%">4. Status &nbsp;
				<b> <apex:outputText value="{!PR['Status__c']}" rendered="{!PR['Status__c']='Complete'}"                                      /></b>
					<apex:inputField value="{!PR['Status__c']}" rendered="{!PR['Status__c']!='Complete'}" id="StatusPL" />
			</td>
		</tr>
		<tr>
			<td class="padding">Notes:</td> 
		</tr>
		<tr>
			<td class="padding">
				<b> <apex:outputText value="{!PR['Notes__c']}" rendered="{!PR['Status__c']='Complete'}"/> </b>
					<apex:inputField styleClass="inputLTextbox" value="{!PR['Notes__c']}" rendered="{!PR['Status__c']!='Complete'}" id="Notes"/>
			</td>
		</tr>
	</table>
	
	<table align="center">
<tr>
<td>
<apex:repeat value="{!PR}" var="PR">
<apex:commandButton value="Submit" style="background: #1895c1; color: #FFFFFF; width: 150px;" onclick="submitOnClick(this);" rendered="{!PR['Status__c'] !='Complete'}"/> 
</apex:repeat>
<apex:actionFunction name="doSubmit" action="{!submitPR}" /> 
</td>
</tr>
</table>
	
<table width="100%">
<tr>
<td style="text-align:right;"><apex:commandLink action="{!savePR}" value="Save" id="SaveLink" style="text-decoration:none; color:blue;"/></td>
</tr>
</table>
</form>

1(你有

var StatusPL

两次脱落。

2(Visualforce以自己的方式生成ID(为其添加层次结构( - 您的"getElementById"不起作用,您需要做其他事情 - 在浏览器中检查您的页面。也许添加类并使用getElementByClass?

最新更新