Required red Mark on a visualforce page -自定义字段如何必填标红

<apex:pageBlockSectionItem >
<apex:outputLabel value="Status" for="Status"/>
<apex:outputPanel styleClass="requiredInput" layout="block"> 
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList id="chooseStatus" value="{!Contact_Exemption_ACU__c.Status__c}" size="1" required="true" >
<apex:selectOption itemValue="Approved" itemLabel="Approved"/>
<apex:selectOption itemValue="Closed" itemLabel="Closed"/> 
</apex:selectList>
</apex:outputPanel> 
</apex:pageBlockSectionItem>

Hey, above is the code to get the red mark for an reqd attribute. Although I have used an standard field, any field can be used in the value in Select List. Also, if you need to display the error message later,following is the code.


<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:inputField id="ACU_held_in_Customer" value="{!Contact_Exemption_ACU__c.ACU_held_in_Customer__c}"/> 
<apex:outputPanel styleClass="errorMsg" layout="block" rendered="{!errorACUheldInCustomer}">
<strong>Error:</strong> {!errorMessage}
</apex:outputPanel>
</apex:outputPanel>

 After doing the validation in the Controller, set the errorACUheldInCustomer to true and set the errorMessage.

以上摘自https://developer.salesforce.com/forums/ForumsMain?id=906F000000095BZIAY

打开debug工具,分析:一般sfdc标准组件,只要加上required=true就会出现如图变红的渲染效果。

在自定义的字段里是没有如图的两个div的,以上解决方法就是把连个class放出来了。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值