You need to sign in to do that
Don't have an account?
"Validation Error: Value is not valid" on drop down
Folk,
I am having one dropdown on Visual Force page. Onchange event i am creating new options for this select using java script. And for this select option one String varible on controller.
VF tag:
<apex:selectList onchange="javascript:change()" id="myselect" size="1" value="{!testSelect}">
<apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList>
JS Funtion:
<script language='JavaScript'>function change(){alert('{!$Component.form.block.myselect}'); tbox = document.getElementById('{!$Component.form.block.myselect}'); clearlistbox(tbox); for(i=0; i < 5 ; i++) { var no = new Option(); no.value = 'karthi' + i; no.text = 'karthi' + i; tbox[i] = no; } } function clearlistbox(lb){ for (var i=lb.options.length-1; i>=0; i--){ lb.options[i] = null; } lb.selectedIndex = -1; }</script>
Controller:
public List<SelectOption> getPicklist(){ List<SelectOption> options = new List<SelectOption>{new SelectOption('Silambarasan','Silambarasan'),new SelectOption('Velu','Velu'),new SelectOption('Banu','Banu')}; return options; } public String testSelect {set;get;}
On clicking the save button i am getting the following error:
j_id0:form:block:myselect: Validation Error: Value is not valid
Full code for VF PAge:
<apex:page standardController="VbApp__c" extensions="VBAPPController" ><script language='JavaScript'>function change(){alert('{!$Component.form.block.myselect}'); tbox = document.getElementById('{!$Component.form.block.myselect}'); clearlistbox(tbox); for(i=0; i < 5 ; i++) { var no = new Option(); no.value = 'karthi' + i; no.text = 'karthi' + i; tbox[i] = no; } } function clearlistbox(lb){ for (var i=lb.options.length-1; i>=0; i--){ lb.options[i] = null; } lb.selectedIndex = -1; }</script> <apex:form ID="form"> <apex:sectionHeader title="Welcom to VB Application"/> <apex:pageBlock id="block"> <apex:pageBlockButtons location="both"> <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> Name:<apex:inputText value="{!vbname}"/><br/> PickList: <apex:selectList size="1" multiselect="false"> <apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList> <br/> Myselect: <apex:selectList onchange="javascript:change()" id="myselect" size="1" value="{!testSelect}"> <apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList> </apex:pageBlock> </apex:form></apex:page>
and
Example for page shows
After changed the dromdown. I am trying to save on this time I am gettingerror "j_id0:form:block:myselect: Validation Error: Value is not valid"
I was able to find a workaround for this issue.
In my case I am using 3 tabs and 2 picklists are used for each tab. So for 3 tabs there are total of 6 picklists.
The issue was values for each pair of picklists were different for each tab. And due to values mismatch it was giving error on tab switch.
So the workaround that I found for this issue is :
I wrote small javascript code that is being called on tab change. Following is the javascript code I used. This refers the picklist and sets its value to empty string :
document.getElementById ('page: myform1:block2:Info1: firstTable: 0:select1').value = '';
document.getElementById ('page: myform2:block2:Info2: secondTable: 1:select2').value = '';
This code just sets the value for each picklist to ' '(Empty String) temporarily. This is the default value for each picklist. So, when the page get loads completely original values overrides this default value and you get the value expected.
This way it does not give any validation error as default value is present in each picklist for each tab.
All Answers
Hi there,
Were you able to resolve it? i have the same issue.
Regards
Mukul
We can do the things in method?
what is your code?
I was able to find a workaround for this issue.
In my case I am using 3 tabs and 2 picklists are used for each tab. So for 3 tabs there are total of 6 picklists.
The issue was values for each pair of picklists were different for each tab. And due to values mismatch it was giving error on tab switch.
So the workaround that I found for this issue is :
I wrote small javascript code that is being called on tab change. Following is the javascript code I used. This refers the picklist and sets its value to empty string :
document.getElementById ('page: myform1:block2:Info1: firstTable: 0:select1').value = '';
document.getElementById ('page: myform2:block2:Info2: secondTable: 1:select2').value = '';
This code just sets the value for each picklist to ' '(Empty String) temporarily. This is the default value for each picklist. So, when the page get loads completely original values overrides this default value and you get the value expected.
This way it does not give any validation error as default value is present in each picklist for each tab.
Hi,
I have grid edit view and the users could not edit multiple documents in the grid. I have to implement dynamic drop down pick lists in the Grid. When I change the value in the controlling pick list field, the values are changing properly in the dependent pick list fields. But when I save the record using an apex controller method, it is displaying an error Validation Error: Value is not valid. Could you please help me out with this?
Thanks,
Srinivas
For my case, it was a dependant picklist, and I was not rerendering the dependent picklist while changing values of the controlling picklist. After rerendering , it works.