You need to sign in to do that
Don't have an account?
Devayani Avadhani Uppu
html placeholder apex:selectlist/apex:selectOption in Visualforce page
Hi All,
I am trying to display a picklist using apex on the Visualforce page with elements apex:selectlist/apex:selectOption, but the html passthrough attribute for place holder doesnt seemed to be working. Below is my code for reference.
<apex:selectList id="businessType" size="1" value="{!businessType}" html-placeholder="Select business type">
<apex:selectOptions value="{!businessTypes}" />
</apex:selectList>
code in controller:
public List<SelectOption> businessTypes {
get {
if (businessTypes == null) {
businessTypes = getbusinessTypes();
}
return businessTypes;
}
private set;
}
private List<SelectOption> getbusinessTypes() {
List<SelectOption> optionList = new List<SelectOption>();
try {
Map<String, Schema.Sobjectfield> corpAppFields = Schema.SObjectType.FXIP_OLAF__c.fields.getMap();
Schema.DescribeFieldResult describe = corpAppFields.get('Business_Entity_Type__c').getDescribe();
List<Schema.PicklistEntry> options = describe.getPicklistValues();
for (Schema.PicklistEntry option : options) {
optionList.add(new selectOption(option.getValue(), option.getLabel()));
}
}
catch(Exception ex) {
System.debug('Unable to load Business Types');
throw ex;
}
return optionList;
}
I am trying to display a picklist using apex on the Visualforce page with elements apex:selectlist/apex:selectOption, but the html passthrough attribute for place holder doesnt seemed to be working. Below is my code for reference.
<apex:selectList id="businessType" size="1" value="{!businessType}" html-placeholder="Select business type">
<apex:selectOptions value="{!businessTypes}" />
</apex:selectList>
code in controller:
public List<SelectOption> businessTypes {
get {
if (businessTypes == null) {
businessTypes = getbusinessTypes();
}
return businessTypes;
}
private set;
}
private List<SelectOption> getbusinessTypes() {
List<SelectOption> optionList = new List<SelectOption>();
try {
Map<String, Schema.Sobjectfield> corpAppFields = Schema.SObjectType.FXIP_OLAF__c.fields.getMap();
Schema.DescribeFieldResult describe = corpAppFields.get('Business_Entity_Type__c').getDescribe();
List<Schema.PicklistEntry> options = describe.getPicklistValues();
for (Schema.PicklistEntry option : options) {
optionList.add(new selectOption(option.getValue(), option.getLabel()));
}
}
catch(Exception ex) {
System.debug('Unable to load Business Types');
throw ex;
}
return optionList;
}
All Answers
For this you have to change in your Controller. Just add the
before the for loop.
Yes we can achieve this by using javascript.