Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Save As Draft with Validation button, which is part of the article here, will validate and save the form data but not completing complete the assignment.

  1. To create a new button, open the form in the form builder.
  2. Create a new section at the bottom of the form.
  3. Edit the section's load binderdata store, and set it to to Bean Shell Form Binderdata store.
  4. In the Bean Shell Form Binderdata store, add in the following code.

    Code Block
    languagejava
    import org.joget.apps.form.lib.SubmitButton;
    import org.joget.apps.form.lib.CustomHTML;
    import org.joget.apps.form.model.Column;
    import org.joget.apps.form.model.Element;
    import org.joget.apps.form.model.FormAction;
    import org.joget.apps.form.model.FormData;
    import org.joget.apps.form.model.Section;
    import org.joget.apps.form.service.FormUtil;
    import java.util.ArrayList;
    import java.util.Collection;
    
    Collection formActions = new ArrayList();
    String saveButtonLabel = "Save As Draft with Validation";
    Element saveButton = new SubmitButton();
    saveButton.setProperty(FormUtil.PROPERTY_ID, "customSaveAsDraft");
    saveButton.setProperty("label", saveButtonLabel);
    formActions.add(saveButton);
    
    
    Section section = element;
    ArrayList columns = (ArrayList) section.getChildren();
    
    
    Column column = columns.get(0);
    column.setProperty("horizontal", "true");
    column.setChildren(formActions);
    
    
    //add a custom html to fix the layout issue
    Element html = new CustomHTML();
    String script = "<script>$(document).ready(function(){";
    script += "$(\"#"+section.getPropertyString("id")+"\").find(\".form-cell\").prependTo(\"#section-actions .form-column\");";
    script += "$(\"#"+section.getPropertyString("id")+"\").remove();";
    script += "});</script>";
    html.setProperty("id", "button_layout_fixes");
    html.setProperty("label", "");
    html.setProperty("value", script);
    formActions.add(html);
    
    
    return null;

     

Related Articles

Temporarily Disable Form Validation on Form Button Click