1

I am unable to get this bit of JS to work. I have a few questions:

  • Am I not allowed to put the disabled attribute on the apex:inputField?
  • Am I importing the JS url incorrectly?
  • Is it possible that the JS can't pick up the values of {!recordTypes}

    <apex:page standardController="Case" extensions="MatterIntakeScreen"  sidebar="false" showHeader="false" showQuickActionVfHeader="false" id="pg">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <!--on the page load, I want to check the value of recordTypes and add the disabled attribute dependant on the value-->
    <script>
    j$(document).ready(function() {
        if('{!recordTypes}' == 'Litigation'){
            $('input[name$="outBalance"]').attr('disabled','disabled');
        }
    }
    </script>
    <apex:slds />
    ...
    
    <div class="slds-form-element slds-size--1-of-4">
        <apex:outputLabel for="outBalance" value="{!$ObjectType.advpm__Matter__c.fields.Outstanding_Balance__c.label}" styleClass="slds-form-element__label" /><br/>
        <apex:inputField id="outBalance" value="{!matter.Outstanding_Balance__c}" styleClass="slds-input" style="width:60%;" />
      </div>
    

Apex

Id recordTypes;
public String getRecordTypes() {
    return recordTypes;
}

public void setRecordTypes(String recordTypes) {
    this.recordTypes = recordTypes;
}
2

Your problem is mostly in your jQuery.

First, you mixed j$ and $. You use the first only if you use jQuery.noConflict (and if you choose to call it j$).

Second, you missed a closing parentheses.

Third, you may want to encode the recordTypes parameter if you expect the possibility of special characters, which can break your code, or use an expression formula.

So, modified, your code would look more like this:

$(document).ready(function() {
    if({!recordTypes="Litigation"}) {
        $('input[name$="outBalance"]').attr('disabled','disabled');
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.