LoginSignup
2
2

More than 5 years have passed since last update.

Salesforceのヘルプテキストアイコンを再現する

Last updated at Posted at 2014-07-29

スクリーンショット 2014-07-29 23.44.58.png

Visualforceでヘルプテキストアイコンを表示するときはpageBlockSectionItemのhelpTextを使って表示できますが、showHeader=falseが指定されたページでは表示されません。

showHeader="false"のページで表示したいときは次の方法でヘルプテキストアイコンを再現できます。

<apex:page showHeader="false">
  <style>
  .vfHelpText img {
    margin-right: 2px;
  }
  .vfHelpText a            {
    position:relative;
  }
  .vfHelpText a span       {
    display: none;
  }
  .vfHelpText a:hover span {
    display: block;
    position:absolute;
    top:1.5em;
    left:1.5em;
    padding:5px 5px;
    z-index:100;
    border:1px solid orange;
    background-color:#FEFDB9;
    color:black;
    font-size: 10px;
    font-weight:normal;
  }
  </style>
  <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
          <apex:pageBlockSectionItem >
            <apex:outputPanel >
              <apex:outputLabel value="ラベル" for="inputKokyakuMei" />
              <span class="helpButton" onfocus="this.className='helpButtonOn';" onmouseout="this.className='helpButton';" onmouseover="this.className='helpButtonOn';">
                <span class="vfHelpText">
                  <apex:outputLink value="javascript&colon;return false;">
                    <img src="/s.gif" alt="" class="helpOrb" />
                    <span>
                      <apex:outputText value="ヘルプメッセージです。" />
                    </span>
                  </apex:outputLink>
                </span>
              </span>
            </apex:outputPanel>
            <input type="text" />
          </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

ちなみにこの方法はshowHeader="true"のページでは正常に表示されません。
showHeader="true"のページでpanelGridなどと一緒に使いたい場合は次のような書き方で対応できます。

<apex:page showHeader="true">
  <apex:form >
    <apex:pageBlock >
      <apex:panelGrid columns="3">
        <apex:outputLabel value="ラベル" styleClass="labelCol" style="padding-right: 0;" />
          <apex:outputPanel >
            <span class="helpButton" id="demo-_help">
              <img src="/s.gif" class="helpOrb"/>
              <script type="text/javascript">
                sfdcPage.setHelp('demo','ヘルプメッセージです。');
              </script>
            </span>
          </apex:outputPanel>
          <input type="text" />
      </apex:panelGrid>
    </apex:pageBlock>
  </apex:form>
</apex:page>

参考

Urgent help - inlineHelp not displaying in Visualforce page, could be silly mistake
https://developer.salesforce.com/forums?id=906F000000096ruIAA

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2