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
Christopher PezzaChristopher Pezza 

Dependant Picklist Does Not Render Class Attribute

I am trying to add a Class to a Input Field in Visual Force but when the page is rendered it removes the styleClass Attribute. This inputField is a dependant Picklist.

Below is my VF Code
<apex:inputField value="{!configTaskToUpdate.Config_Category__c}" styleClass="form-control" id="thecategory"/>

i have tried adding the the code to a div tag around it but it comes out akward

I have also tried adding it to the the field by jQuery as below but that doesnt work either
$(document).ready(function() {
                    $(function() {
                        $("#{!$Component.theform.thecategory}").addClass("form-control");
                        console.log('added the form-control class');
                    });
                });

Anyone have this issue and or found a workaround or is SF working on it?
Best Answer chosen by Christopher Pezza
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Christopher Pezza:

 In case of Jquery in salesforce, there is a different approach to identify the components based on ids in case it is a visualforce tag (not standard html tag).

you need to refer as:

 $('[id*=thecategory]').,

for more info on using jQuery, refer to below link:

https://developer.salesforce.com/page/Developing_Apps_with_jQueryv
And one more thing., in Visualforce pages, once the page is rerendered upon an action, jQuery looses its scope of the compoenent., I can suggest you to use .live function in jQuery in case you are using 1.7 version or earlier.

Thanks,
Balaji

All Answers

Vishnu VaishnavVishnu Vaishnav
Hi Christopher,

Got it, just try these steps:
1. Create a javascript function, put the 
  $("#{!$Component.theform.thecategory}").addClass("form-control");
  code in this function.

2. I think u r using some button or action function to rerender the page. Is it right ?
    on action function or button put a attribute oncomplete=YourJavscriptFunction
like; <apex:actionfunction name="myfun" action="{!BlahBlah}" oncomplete="YourJavscriptFunction">

:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Christopher Pezza:

 In case of Jquery in salesforce, there is a different approach to identify the components based on ids in case it is a visualforce tag (not standard html tag).

you need to refer as:

 $('[id*=thecategory]').,

for more info on using jQuery, refer to below link:

https://developer.salesforce.com/page/Developing_Apps_with_jQueryv
And one more thing., in Visualforce pages, once the page is rerendered upon an action, jQuery looses its scope of the compoenent., I can suggest you to use .live function in jQuery in case you are using 1.7 version or earlier.

Thanks,
Balaji
This was selected as the best answer
Christopher PezzaChristopher Pezza
both of them worked together thank you both!