【问题标题】:inputField required mark with custom error msgs带有自定义错误消息的输入字段必填标记
【发布时间】:2012-11-09 14:07:53
【问题描述】:

我正在使用直接绑定到控制器中的自定义对象字段的 inputField。 下面会生成一个带有标签的下拉列表。

 <apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" />

我的问题是我需要在 inputField 旁边添加所需的标记,而不会丢失标签或默认错误消息。

当我使用时

<apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" required="true"/>

我获得了所需的标记,但我丢失了用于验证的自定义错误消息。

当我使用时

<apex:outputPanel styleClass="requiredInput" layout="block">
     <apex:outputPanel styleClass="requiredBlock" layout="block"/> 
     <apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" />
  </apex:outputPanel>

下拉列表附近的标签不再显示..

有什么方法可以完成我需要的吗?

【问题讨论】:

    标签: salesforce visualforce input-field


    【解决方案1】:

    我最终使用了这个。

    //this part to add the missing label.
    <apex:outputLabel styleclass="labelCol" value="{!$ObjectType.Agency_Profile__c.fields.Location_Principal_Activity__c.Label}" />
    
    <apex:outputPanel styleClass="requiredInput" layout="block">
         <apex:outputPanel styleClass="requiredBlock" layout="block"/> 
         <apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" />
      </apex:outputPanel>
    

    【讨论】:

      【解决方案2】:

      最好的方法是为这个对象的这个字段添加validation rule

      【讨论】:

      • 添加不会在visualforce页面中的字段附近显示红色标记。
      • 我会检查的。但甚至应该有一个输入错误消息的字段。
      【解决方案3】:

      使用 raym0nds 方法,这就是它查找 自定义控制器变量的方式,在我的例子中,名称来自对象的自定义字段。:

      //this part to add the missing label.
      <apex:outputLabel for="myId" styleclass="labelCol" value="{!$ObjectType.Agency_Profile__c.fields.Location_Principal_Activity__c.Label}" />
      
      <apex:outputPanel styleClass="requiredInput" layout="block">
           <apex:outputPanel styleClass="requiredBlock" layout="block"/> 
           <apex:inputText id="myId" required="true" value="{!myCustomField}" label="{!$ObjectType.Agency_Profile__c.fields.Location_Principal_Activity__c.Label}"  />
      </apex:outputPanel>
      

      注意apex:inputText 类型,它现在具有labelidrequired 属性。 apex:outputLabel 现在有一个 for 属性。 for/id 就是这样,单击标签会将光标置于右侧字段中。 required 启用表单验证,因为其余的只是化妆。 label 为该验证错误添加了一个好的字段名称 - 否则它将在那里显示内部字段 ID。

      如果您有一个所有记录共享某些值的批量编辑表(例如,为同一家公司添加多个潜在客户),那么整个方法会很有趣

      【讨论】:

        猜你喜欢
        • 2015-05-14
        • 1970-01-01
        • 2023-04-07
        • 2012-11-27
        • 2022-12-21
        • 1970-01-01
        • 2018-03-18
        • 2014-08-07
        • 1970-01-01
        相关资源
        最近更新 更多