You need to sign in to do that
Don't have an account?
![Michael Hedrick 2 Michael Hedrick 2](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Validate Visualforce Fields prior to Save
Hello,
I have a Visualforce page that performs the following:
The issue is that I have required fields and a message alert the user that the field is required but the issue is that the
Can the values be checked prior allowing the user select the 'Save' button?
M
I have a Visualforce page that performs the following:
- saves record
- shows success message
- closes VF page
- refreshes salesforce page
<apex:commandButton action="{!save}" value="Save" onclick="setTimeout(Closewindow, 5000)" id="saveButton" reRender="Panel" /> <apex:commandButton value="Cancel" onclick="window.close();" immediate="true"/> </div> <apex:outputPanel id="Panel" style="font-size:16px;color:red"> <apex:messages /> </apex:outputPanel>
The issue is that I have required fields and a message alert the user that the field is required but the issue is that the
onclick="setTimeout(Closewindow, 5000)"still runs. So the VF pages closes without saving the record.
Can the values be checked prior allowing the user select the 'Save' button?
M
All Answers
Thank you for the reply. I understand that I can put checks in the Controller like this:
But will it keep the VF page from closing since the syntax below is still in the commandbutton? I have a function in the VF page that closes the window and refreshes the details page. Can the timer go in there?
Thanks for your help. Your suggestion does work but I decided to use the following approach instead.
- Made all the neccessary fields required on teh VF Page
- Removed the JS call from the Command Button.
- Call the JS function that is in the Visualforce Page from the Apex Class.
Here is the complete code for anyone that might be trying to do the same thing.Apex
VF Page