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
Greg MeszarosGreg Meszaros 

Rerender Page based on inputfield

I have a visualforce page that, amongst other things, contains 2 fields. One is a State field and the other is a County field. The County field contains a list of all the Counties in a "Tax Zone" custom object.

I am trying to modify the code so that the County list only contains Counties from whatever State has been typed in the State field. There is currently a getter method that runs on page load that adds items in the County list field regardless of the state.

I want to use rerender to accomplish this but I am new to development and a little out of my league here. Can someone please help???

Here is the VF page:
<apex:inputField type="text" html-ff="Desking:frm:county" styleClass="form-control" style="text-transform: uppercase;" id="state" value="{!dealer__Deal__c.State__c}" >
     <apex:actionSupport event="onchange" rerender="county" />             
</apex:inputField>



<apex:inputField type="text" html-ff="Desking:frm:courtesyreserve" styleClass="form-control left-text" id="county" value="{!dealer__Deal__c.dealer__County__c}" list="{!TaxZoneCountyList}" html-oninput="setTaxRate();" onchange="setTaxRate();"/>
Here is the class:
public List<String> getTaxZoneCountyList () {
        String[] taxCounties = new String[]{};
        for(dealer__Tax_Zones__c tx : [select Id, dealer__City__c, dealer__County__c, dealer__State__c from dealer__Tax_Zones__c limit 500]) {
            taxCounties.add(tx.dealer__County__c);
        }
        return taxCounties;
}

 
Best Answer chosen by Greg Meszaros
Greg MeszarosGreg Meszaros
I was able to solve the problem by modifying the code in my class as follows:
 
public List<String> getTaxZoneCountyList () {
        //Ternary If Statement - If there is no value in that field, default back to deal's state.
        state = ApexPages.currentPage().getParameters().get('Desking:frm:state') == null ? deal.State__c : ApexPages.currentPage().getParameters().get('Desking:frm:state');
        String[] taxCounties = new String[]{};

        for(dealer__Tax_Zones__c tx : [select Id, dealer__City__c, dealer__County__c, dealer__State__c from dealer__Tax_Zones__c WHERE dealer__State__c =:state limit 500]) {
            taxCounties.add(tx.dealer__County__c);
        }
        return taxCounties;
    }