Find your content:

Search form

You are here

Add some custom Id into inputField - dependent picklist

 
Share

I have in controller inner class with sobject and custom id. In visualforce page I have apex repeat over this inner classes. In repeat block are two fields (picklists) which are dependent. Everything works fine, but I need to add my custom Id as styleClass to these fields. For example:

<apex:repeat value="{!lst}" var="s"> 
<apex:inputfield value="{!s.Oli.field1__c}" styleclass="{!s.customid}" />
<apex:inputfield value="{!s.Oli.field2__c}" styleclass="{!s.customid}" />
</apex:repeat>

my class

public myController {
 public list<OliRow> lst {get;set;}
 public class OliRow{
   public OpportunityLineItem Oli {get; set;}
   public customId {get;set;}
   public OliRow(OpportunityLineItem thisOli){
     oli = thisOli;
    //logic for populat customId
   }
 }

   public myController(){
      lst = new list<OliRow>();
      for(OpportunitylineItem objOli : [SELECT id,...FROM OpportunitylineItem WHERE ..]){
         lst.add(new OliRow(objOli));
      }
      //other logic
   }
}

In this scenario my picklist do not have these styles. I tried htm5 params:

<apex:inputfield value="{!s.Oli.field1__c}" html-data-id="{!s.customid}" />

but it not works too.

I need this customid id for javascripts.

please Do not care of this apex code, which works perfect. CustomId is random string with some logic. If I put it there it will be only confused. I try to eplain it in other way

<apex:repeat value="{!lst}" var="s"> 
    <apex:inputfield value="{!s.Oli.field1__c}" styleclass="{!s.customid}" /> <!-- controlling field-->
    <apex:inputfield value="{!s.Oli.field2__c}" styleclass="{!s.customid}" />  <!-- depended field-->
    <apex:inputfield value="{!s.Oli.field3__c}" styleclass="{!s.customid}" /> <!-- not depended field -->
 </apex:repeat>

HTML which I get in salesforce for one line is (in short form)

<select id="salesforceGeneratedId"><options for field1 >...</select>
<select id="salesforceGeneratedId2"><options for field2 >...</select>
<select id="salesforceGeneratedId3" class="mycustomid"><optios for field3>...</select>

My problem is why I do not have class="mycustomid" for first 2 select (picklist)

EDIT
I put quotes (at first it did some wrong formats for code here)
I put here sample class
highfive: I put how I populate lst, but it do not affect on my problem, as I said everything works fine, insted of add customid as styleClass. When I look at the HTML of page, do bot have my attributes, only salesforce id and name (I can use it for my purpouse)
Add new example


Attribution to: MarosSitko

Possible Suggestion/Solution #1

In order to help you out, we need an accurate representation of your code from the get go. That being said, the following line is commented out: //logic for populat customId. Since this is commented out, customId is never set, and as a result, you will not have your style attribute populated in visualforce.

If you're just commenting it out for the sake of the question, please put it in so we can help further.


Attribution to: James Loghry

Possible Suggestion/Solution #2

The styleClass attribute (and others) does not work for <apex:inputField> when it is a dependent picklist. I would just wrap it with an <apex:outputPanel> and set the styleClass there. Then in javascript detect when it's a dependent picklist and get the child select element of the <apex:outputPanel>.


Attribution to: George S.
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32159

My Block Status

My Block Content