Last active
May 11, 2021 13:10
-
-
Save anil826/22e05008e88d24f2beefafe1a2c4b041 to your computer and use it in GitHub Desktop.
Custome Javascript Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".finish").on("click", function (ev) { | |
ev.stopImmediatePropagation(); | |
let isValid = true; | |
//Loop on all formyoula fields | |
Object.keys(formyoula.form_fields).forEach(function(component_id) { | |
//Regex for element component id | |
if (/^[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}$/.test(component_id)) { | |
//Get component | |
let component = formyoula.form_fields[component_id]; | |
//Check if component attribute is available and value is empty | |
if ( component.attributes && component.attributes.required && _.isEmpty( component.attributes.value ) ) { | |
isValid = false; | |
} | |
} | |
}); | |
if ( !isValid ) { | |
//Show the custome Error message | |
window.formyoula.show_alert({message: 'Please check the requried Field', title: 'Required Field Error'}); | |
return false; | |
} | |
//Submit the form | |
$(".finish").off("click").click(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment