I am looking for help from Visualforce (Salesforce) page guru.
Background: There is a drop down list (apex:selectList in terms of Visualforce page). Its select options are built by jQuery with returned data (in JSON format) from RemoteAction (in Controller).
Problem: it always reports error message (j_id0:j_id2:j_id3:j_id4:orgList: Validation Error: Value is not valid) when I click command button which sends selected item value to Controller.
Any thoughts? Thanks very much.
Troy
Visualforce markup:
<apex:panelGrid columns="2">
<apex:selectList id="orgList" value="{!selected}" size="1">
</apex:selectList>
<apex:commandButton value="Add" action="{!add}" style="width:80px">
</apex:panelGrid>
JavaScript:
$j("input[id$='azc']").keyup(function(){
var op = $j("select[id$=orgList]");
if($j(this).val().length >= 6){
op.empty().append('<option value=""></option>');
OrgController.findOrgs($j(this).val(), function(result, event){
if(event.status){
var data = $j.parseJSON('[' + result.replace(/'/g, '"') + ']');
$j.each(data, function(){
$j('<option />', {value: this['value'], text: this['label']}).appendTo(op);
});
}else{
alert(event.message);
}
},{escape:true});
}
OrgController
public String selected { get; set; }
public PageReference add(){
Customer__c customer = findSelected(selected);
if(customer != null){
customer.Pending__c = 'Yes';
update customer;
}
return null;
}
I would try to use a normal (html) select list and send selected value to controller per hidden field like this (works for me):