function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tofertektofertek 

DatePicker missing on Rerender

 

I am trying to reveal an <apex:inputField> dynamically, specifically a date field.  It is part of an "Additional Info" pageblock section that looks like this.
<apex:pageBlockSection id="additionalInfo" title="Additional Status
Info">
    <apex:inputField rendered="{!show_a1}" value="{!mii.AI_01_Date__c}"/>
......
Above this, I have a nifty selection that forces a rerender of this pageBlockSection
<apex:inputField value="{!mii.Status__c}" >
   <apex:actionSupport event="onchange" action="{!filterMandatoryInput}"
                       rerender="additionalInfo"/> 
</apex:inputField>

 

So that is working fine.  When a user selects a status dropdown, additionalInfo rerenders, the show_a1 boolean gets flipped accordingly, and the AI_01_Date field suddenly appears.

The problem is that the screen did not originally render with a Date input field, so the DatePicker code did not get appended to the bottom of the page.  Long story short, the calendar does not pop up when you select inside of this date field.

 

Any suggestions as to how to include the DatePicker code on a visualforce page without starting the page with an inputfield linked to a Date field?

 

Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
mulvelingmulveling

Since this is going to be an unused hidden field, it need not be laid out carefully within a pageBlockSection (which will indeed spawn a label column for each of its inputField children, in addition to the UI elements spawned for the date-type inputFields). Furthermore, you can better hide such an element by wrapping it in a <div> and then hiding THAT. Here's essentially what I did:

 

 

<apex:form>
    <div style="display:none"><apex:inputField value="{!mii.zzUnusedDate__c}" /></div>

    <!-- Your carefully crafted page goes here -->

</apex:form>

 

 

All Answers

mulvelingmulveling

I ran into this problem a while ago. I just put a different, unused date inputField on a part of the page that would always be rendered, and with a style="display:none" to hide it - with a comment to explain why this otherwise superfluous element was needed. Not elegant, but it forces the page to include the date-picker scripts, and I was able to go about my merry way.

tofertektofertek

Thanks for the suggestion.  that lead me to 2/3 of a solution, but did not take me all the way home.

 

A date is a combination of :

- the label naming the field

- the inputbox where clicking inside should render the calendar widgit

- the current date suggestion hyperlink.  clicking this fills in the date input field with the current date

 

Using the entry below, i can get rid of the first two, but not the stupid hyperlink.

 

 

            <apex:pageBlockSection id="foo" title="" >
                <apex:pageBlockSectionItem labelStyle="display:none">
                    <apex:inputField value="{!mii.zzUnusedDate__c}" style="display:none"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection> 

 The style change in the input field only got rid of the input box itself.  The "zzUnusedDate" label was still there, and the Now() hyperlink was as well.  Fudging around, i used the pageBlockSectionItem and the labelStyle attrib, and got the "zzUnusedDate" label to disappear.  Now I am left with that hyperlink.

 

Any ideas?  If i can't come up with something, then i have to shove it on the top and say "Today's date is:"  , which is kind of dumb.  Not beyond me though.

 

Thanks again.

 

mulvelingmulveling

Since this is going to be an unused hidden field, it need not be laid out carefully within a pageBlockSection (which will indeed spawn a label column for each of its inputField children, in addition to the UI elements spawned for the date-type inputFields). Furthermore, you can better hide such an element by wrapping it in a <div> and then hiding THAT. Here's essentially what I did:

 

 

<apex:form>
    <div style="display:none"><apex:inputField value="{!mii.zzUnusedDate__c}" /></div>

    <!-- Your carefully crafted page goes here -->

</apex:form>

 

 

This was selected as the best answer
tofertektofertek

When i took that out from under a pageBlockSection, and put it directly under the <apex:form > tag, it worked!

 

Thanks for you help!  This is my first experience with forum questions, and it was a good one.  Back on schedule.