I'm trying to assign Id to my inputField dynamically, those input fields are coming from field sets.
These Ids needs to be assigned to those fields which are required in database.
On giving Id dynamically I'm getting Literal value is required for attribute id in error.
Based on those ids I need to perform some check in javascript, before saving the record.
<apex:outputPanel id="mySalesforceFields">
<apex:repeat value="{!fieldSetMemberList}" var="field">
<apex:inputField value="{!sObject[field]}" required="{!if((field.dbRequired || field.required), true,false)}"
id="{!if((field.dbRequired || field.required), field.label,'')}" />
</apex:repeat>
</apex:outputPanel>
Best Answer
You can't dynamically assign the Visualforce
id
attribute. You can, however, assigndata-
attributes or pass throughhtml-
attributes. See, for example, Setting Custom HTML Attributes on Visualforce Components . Make sure you use a unique value such as the field's API Name rather than its Label if you decide to pass through anhtml-id
.Probably better to use
data-
attributes. You can still select on them.