Tag Archives: HTML5

Immediate=true is not working on custom buttons with HTML5 docType in Visualforce Page

If you are setting your docType="html-5.0" and having a validation error on cancel, after the immediate="true" for a command button, action function etc.
Here are two options for disable all validation for all command buttons and disable validations for specific command button.

Option 1:
If your requirement is to disable all validation for entire page, then you can add html-novalidate="novalidate" attribute to apex form. This will disable all validations for all command buttons.

<apex:page standardController="Account" docType="html-5.0">
	<apex:form html-novalidate="novalidate">
		<apex:pageBlock title="Account Information">
			<apex:pageBlockButtons location="bottom">
				<apex:commandButton action="{!Cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:pageBlockSection>
				<apex:inputField value="{!Account.Name}" required="true" ></apex:inputField>
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

Option 2:
If your requirement is to disable the validation for specific command button, then you can add immediate="true" and html-formnovalidate="formnovalidate" attribute to that command button. This will disable all validations for all command buttons.

<apex:page standardController="Account" docType="html-5.0">
	<apex:form>
		<apex:pageBlock title="Account Information">
			<apex:pageBlockButtons location="bottom">
				<apex:commandButton action="{!Save}" value="Save" />
				 <apex:commandButton action="{!Cancel}" value="Cancel" immediate="true" html-formnovalidate="formnovalidate" />
			</apex:pageBlockButtons>
			<apex:pageBlockSection>
				<apex:inputField value="{!Account.Name}" required="true" ></apex:inputField>
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>