Skip to content

Instantly share code, notes, and snippets.

@anil826
Last active May 11, 2021 13:10

Revisions

  1. anil826 revised this gist May 11, 2021. 1 changed file with 22 additions and 12 deletions.
    34 changes: 22 additions & 12 deletions validation.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,23 @@
    //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 ) ) {
    //Show the custome Error message
    window.formyoula.show_alert({message: 'Please check the requried Field', title: 'Required Field Error'})
    }
    }
    $(".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();
    });
  2. anil826 created this gist May 11, 2021.
    13 changes: 13 additions & 0 deletions validation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    //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 ) ) {
    //Show the custome Error message
    window.formyoula.show_alert({message: 'Please check the requried Field', title: 'Required Field Error'})
    }
    }
    });