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
justin_sfdcjustin_sfdc 

<apex:inputfield>

Can I give an "id" the value in following manner while using <apex:inputfield> component?

 

<apex:inputField value={!x} id ="{!value}" />

 

What am trying to achieve here is; I have this inputField inside an <apex:repeat> component and I need to give it a separate id everytime this component gets repeated.

 

Any suggestion is helpful.

 

Thanks ~ justin_sfdc

Best Answer chosen by Admin (Salesforce Developers) 
amarcuteamarcute

Hi,

 

Is this what you are looking for?

 

<apex:page controller="myTestController">
   <apex:variable value="{!0}" var="rowNum"/>
   <apex:repeat value="{!myList}" var="f">
       <input type="text" name="Account" id="exampleId{!rowNum}" value="{!f}"></input>  
       <apex:variable var="rowNum" value="{!rowNum + 1}"/>  
   </apex:repeat>
</apex:page>
public with sharing class myTestController {
  
  public myTestController() {
 
  }
  
    public List<Integer> getMyList() {
       List<Integer> myList = new List<Integer>(); 
       myList.add(1);
       myList.add(2);
       myList.add(3);
       return myList;      
    }
}

 

 

 

All Answers

amarcuteamarcute

Hi,

 

Currently it's not possible to use an expression as an ID for a visualforce component.  There is an Idea to support that @ https://success.salesforce.com/ideaview?id=08730000000Bqu1AAC

Samba GSamba G

I think you can use this.

apex:variable

 

 

Thanks,

Samba

justin_sfdcjustin_sfdc

Hi,

 

Thanks for the reply. I see that we can achieve it using the generic html input field.

Could you give me an example of how i would be using <apex: repeat> component and html input field at the same time.

and the id value in it should be in incrementing order. for example; if we are entering an address in the field then the id for it should be id="address{!number}", where the number will increased by one everytime the repeat coomponent is called.

 

Thanks a lot!

justin~sfdc

Sgt_KillerSgt_Killer

Try having a function in your controller or extension which increments an integer and return the string value of that integer. Instead of creating input field using VF try using the HTML code.

 

 <input type="text" name="Account" id="{!y}" value="{!x}"></input>

 

where {!y} is the method that return the incremented Integer value in a String format(using String.valueof(Integer))

and {!x} is the method that processes your input value.

 

with regards,

Sgt_Killer

amarcuteamarcute

Hi,

 

Is this what you are looking for?

 

<apex:page controller="myTestController">
   <apex:variable value="{!0}" var="rowNum"/>
   <apex:repeat value="{!myList}" var="f">
       <input type="text" name="Account" id="exampleId{!rowNum}" value="{!f}"></input>  
       <apex:variable var="rowNum" value="{!rowNum + 1}"/>  
   </apex:repeat>
</apex:page>
public with sharing class myTestController {
  
  public myTestController() {
 
  }
  
    public List<Integer> getMyList() {
       List<Integer> myList = new List<Integer>(); 
       myList.add(1);
       myList.add(2);
       myList.add(3);
       return myList;      
    }
}

 

 

 

This was selected as the best answer
justin_sfdcjustin_sfdc

Hi,

On doing this, I get an error message saying Attribute "value" was already specified for element "apex:variable"

 

I am utilizing this component outside the repeat component and again inside the repeat component with the var being "rowNum" just like the one you showed.

 

Any mistake am i doing in here?

 

Thanks and Regards,

Justin~sfdc

 

justin_sfdcjustin_sfdc

Hi,

Please disregard my previous email. I was able to get different id's everytime the repeat component is executed. 

 

Thanks a lot! 

Justin~sfdc

 

 

 
justin_sfdcjustin_sfdc

Hi Amarcute,

 

With your help I am able to achieve separate id's in the repeat block. However, I could not direct the input tag to the SFDC custom field. 

 

For example; If i have a custom Object called as "Address__c" and there is a field called "country__c"

Now in the input tag; whatever value the user inputs; i want to save it in that field. How would I do it?

So far I have;

 

<apex:variable value={!0} var ="rowNum" />

<apex: repeat value= {!myList}" var="f">

    <apex:outputLabel value="country" for ="Country" />

    <input id="Country{!rowNum}" required="true" /> //How do i direct it to the country__c field in Address__c object?

<apex:variable var="rowNum" value="{!rowNum + 1}"/>  
</apex:repeat>

 

Thanks a lot!

Justin~sfdc