2

I have a command link in my vf page and an input text. I am trying to initially have the command link as disabled and when a user enters the text in the input then command link becomes enable and if the input text is empty then disable the command link. below is the code.Any solution using the controller or jquery is accepted. thanks

 <apex:commandLink value="Calculate End Date" action="{!calculateEndDate}"
                                           reRender="RecurrsiveDetails" ></apex:commandLink>
      <apex:input type="date" value="{!startDateRec}" label="Start Date" onchange="enableCalculateEndDate()"/>
1
  • 2
    look at actionSupport on the apex:input
    – cropredy
    Apr 22, 2016 at 17:33

1 Answer 1

0

Normally, you could just bind the disabled attribute of your commandButton/outputLink, and use an actionSupport to rerender it when the input changes. In this case, since you really want to use a commandLink, you'll have to do something a little less direct because that component does not have a disabled attribute:

<apex:outputPanel id="linkPanel">
    <apex:commandLink id="calculateLink" value="Calculate End Date" action="{!calculateEndDate}" rendered="{!NOT(ISBLANK(startDateRec))}" reRender="RecurrsiveDetails" />
    <apex:outputText value="Calculate End Date" rendered="{!ISBLANK(startDateRec)}"
</apex:outputPanel>
<apex:input type="date" value="{!startDateRec}" label="Start Date" >
    <apex:actionSupport event="onchange" rerender="{!$Component.linkPanel}" />
</apex:input>
8
  • it gives error open quotes is needed for attribute disabled associated with element type <apex:commandlink /> Apr 22, 2016 at 19:56
  • Oops, yes it looks like I forgot to put double-quotes around the bind expression there. I have updated my answer. Apr 22, 2016 at 20:20
  • If this answer helped you, please do not forget to mark it as solution :) Apr 25, 2016 at 14:28
  • It still says in my command link as an error that the attribute disabled is not supported Apr 25, 2016 at 14:29
  • <apex:outputPanel layout="block"> <apex:input type="date" value="{!endDateRec}" label="End Date"/> <apex:commandLink value="Calculate End Date" action="{!calculateEndDate}" reRender="RecurrsiveDetails"></apex:commandLink> </apex:outputPanel> when i add your command link it gives the error Apr 25, 2016 at 14:32

Not the answer you're looking for? Browse other questions tagged .