You need to sign in to do that
Don't have an account?
john8407
Autosave in background
In a scenario where I have a field that is required if another is a certain value, is there any way to have the record save in the background without reloading and the user noticing anything? I'm asking cause I want to include the required with an if statement on the other field.
Not quite sure how to code it, but what if
1. set the required value of the dynamically required field to an {!IF(variable=xxx,true,false)}
2. you put the field that is dynamically required in a seperate component wrapper
3. and then when the field that detemins the required fields status is changed call
4. a javascript function that rerenders the component with the dynamically required field
**UPDATED WORKING**
Ok, I have a solution but it needs one thing: properly setting the variable to the value entered in the field
Controlling field = FieldA
Dependent Field = FieldB
Controller Variable = VarA
Entry to make required = 'Mine'
1. Add around FieldB
<apex:outputPanel id="test">
<apex:InputField id="FieldB" value="{!object.Field}" required="{!IF(VarA=='**Whatever you want it to be to make other required**',True,False)}" />
</apex:outputPanel>
2. Make this where the controlling FieldA is
<apex:inputField id="FieldA" value="{!object.field}" required="true" onchange="getInputValue()">
<script>
function getInputValue(){
var ex = document.getElementById('{!$Component.FieldA}').value;
passValue(ex)
}
</script>
</apex:inputField>
3. In the form add somewhere
<apex:actionFunction name="passValue" action="{!gValue}" immediate="True" rerender="test">
<apex:param name="myParam" value=" "/>
</apex:actionFunction>
4. In the controller
Public String VarA{get;set;}
Public void gValue(){
VarA = ApexPages.CurrentPage().getParameters().get('myParam'');
}
Here is a working example:
Controller:
Visualforce Page:
Thank you Starz26! One question. I can't get it to work in a pageBlockSection and pageBlockSectionItem. Do you know how?
Sure, remove the outputpanel and replace the code section with this:
It will require the field based on the value you enter in the controlling field as well as make the section not collapsible based on the controlling field.