I have a Visualforce page which I've just moved from my Sandbox into production. The page is meant to be a wizard for creating component objects. The Save & New inserts the new component, then refreshes the page to create a new component. I have a field Plate_Type__c
which is a drop down field. It has a dependent field Number_Of_Channels_Per_Volume__c
another drop down field which itself has a dependent field Dispensing_Pattern__c
. When in the Sandbox Number_Of_Channels_Per_Volume__c
was grayed out and inaccessible, until Plate_Type__c
was selected, as expected.
However now that it is in production occasionally after entering one component and clicking Save & New once the page refreshes and I select a value for Plate_Type__c
, Number_Of_Channels_Per_Volume__c
remains grayed out and inaccessible. Luckily I have validation related to these fields. So if I subsequently click Save or Save & New my validation rules throw their exceptions. Every time I've done this Number_Of_Channels_Per_Volume__c
is no longer grayed out and I can continue.
I can't find a consistent set of events which makes this happen. Occasionally it will happen as I go through multiple times in a row and then go back to the expected behavior before returning to the undesired behavior again.
I'm not very familiar with Javascript so I wouldn't be surprised if it is in someway related to how the script is set up in my page. That or perhaps it has something to do with field permissions.
Here is the VF:
<apex:page standardController="Consumable_Analysis_Component__c" extensions="ConAnalysisController" wizard="true" >
<script>
function confirmCancel(){
return confirm("Are you sure you meant to cancel this?");
}
function launchWindow(){
window.open('/apex/ComponentWizardHelpPage');
}
function disableOnSubmit(input) {
var btn = input;
setTimeout(function(){ btn.disabled = 'disabled'; btn.className = 'btnDisabled'; btn.value='Saving...';},50);
}
function setFocus(){
document.getElementById('{!$Component.form.block.blsx.volumeDispensed}').focus();
}
</script>
<apex:sectionHeader title="Consumable Analysis Component Edit" subtitle="New Consumable Analysis Component"/>
<apex:pageMessages id="errorMssg" />
<apex:form id="form">
<apex:pageBlock id="block" title="Consumable Analysis Component Edit" mode="edit">
<apex:pageBlockButtons location="bottom" >
<apex:commandButton action="{!savenew}" value="Save & New" onclick="disableOnSubmit(this);" />
<apex:commandButton action="{!save}" value="Save" onclick="disableOnSubmit(this);" />
<apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel();" immediate="true"/>
<apex:commandButton value="Help" onclick="launchWindow();" immediate="true"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" id="blsx" >
<apex:outputField value="{!component.RecordTypeId}" id="recordType" />
<apex:outputField value="{!component.Solution_Analysis__c}" id="analysis" />
<apex:inputCheckbox value="{!component.Alt_Sol_Ver__c}" id="altSolVerif" />
<apex:inputField value="{!component.Aqu_DMSO__c}" id="aqueousDMSO" />
<apex:inputField value="{!component.Vol__c}" id="volumeDispensed" />
<apex:inputField value="{!component.Plate_Type__c}" id="plate" />
<apex:inputField value="{!component.Number_Of_Channels_Per_Volume__c}" id="channels" />
<apex:inputField value="{!component.Dispensing_Pattern__c}" id="pattern" />
<apex:inputField value="{!component.Full_Disp_Unrv__c}" id="rowsColsPlates" />
<apex:inputField value="{!component.Number_Of_Devices__c}" id="devices" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script>
<body onload="setFocus()">
</script>
</apex:page>
And here is the Save & New function from Apex:
public PageReference savenew(){
try{
insert component;
} catch(System.Exception e){
ApexPages.addMessages(e);
return null;
}
component = new Consumable_Analysis_Component__c();
component.Solution_Analysis__c = parentId;
component.RecordTypeId = Schema.SObjectType.Consumable_Analysis_Component__c.getRecordTypeInfosByName().get('MVS').getRecordTypeId();
component.Aqu_DMSO__c = 'Aqueous';
return null;
}
rerender
attribute on your commandButton?rerender
attribute in order to disable the button rather than the JS? In that case yes, I don't remember the detail but settled on the approach above. If you mean something else please elaborate. As far as the console it looks like when the error occurs the console throwsUncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement.picklist.onControllerChange (picklist4.js:21) picklist.onControllerChange @ picklist4.js:21