question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manually validate forms

See original GitHub issue

Using the open sourced project, how would I manually validate the forms prior to submission.

Im not using the submit button provided by the form, instead, im trying to doing a manual submission instead but am unable to trigger the form validation where errors show up like it would here https://files.catbox.moe/wm3q2z.png

I came across the code _form.checkValidity(_form.submission.data); found here but that always return true.

Ive also tried to set the form element to form (<form id='trespassersForm'></form>) and call _$trespassersForm.validate(); but that also always return true.

i also came across this post but i have no need for server validation since the data will be saved in the formio mongodb.

The idea behind this is that i want to keep the form in a modal window to stay consistent with an already existing website. The modal window has its own save button which triggers the formio.canSubmit() line of code.

Heres what the modal looks like (rather use save button than submit button)

// modal window

        var formio = new Formio(formUrl);
       _$trespassersForm = $('#trespassersForm'); // document.getElementById('trespassersForm');

       // Formio.icons = 'fontawesome';

       Formio.createForm(_$trespassersForm[0], formUrl).then(function(form) {

        // Pre-populate values if in edit
        if (model.isEditMode) {
         new Formio(submissionUrl).loadSubmission().then(function(results) {
          form.submission = {
           data: results.data
          };
         });
        }

        // Register for the submit event to get the completed submission.
        form.on('submit', function(submission) {
         console.log('Submission was made!', submission);
        });

        // Everytime the form changes, this will fire.
        form.on('change', function(changed) {
         submissionData = changed;
        });

       });
       .....

this is called when the save button on the modal is pressed need to validate here where validation messages show up in the form as if i pressed the button

       formio.canSubmit().then(function(canSubmit) {
        if (canSubmit) {

         _modalManager.setBusy(true);

         try {
          var data = app.forms.submission.setAuditingValues(submissionData, model);
          formio.saveSubmission(data).then(function(didSubmit) {
           console.log('Did submit', didSubmit);
           abp.notify.info(app.localize('SavedSuccessfully'));
           _modalManager.close();
           abp.event.trigger('app.createOrEditTrespassersModalSaved');
          }).catch(e => {
           console.log(e);
           abp.notify.error(e);
          });
         } catch (err) {
          console.error(err);
         } finally {
          _modalManager.setBusy(false);
         }
        }
       });

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
152hqcommented, Dec 9, 2018

alternatively, you can also use

form.submit(); // form is the form-instance that you have after form is rendered.

1reaction
hisuwhcommented, Aug 5, 2020

Thanks @randallknutson yes its very similar. I couldn’t find that method and ended up going a different way. But for other peoples benefit:

<template>
    <Form :ref="formioForm" />
</template>
<script>
export default {
    name: "MyComponent",
    methods: {
        validate() {
            this.$refs.formioForm.formio.checkValidity();
        }
    }
}
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Validating form manually - FormValidation
Validating form manually ... In most cases, the form can be validated automatically when user click its Submit button via the SubmitButton plugin....
Read more >
How do you manually trigger the form validation in Blazor?
You have to define and bind the EditContext with EditForm and then call the method editContext. Validate() on button click to manually trigger ......
Read more >
Validate a form manually in React Js - CodeSpeedy
There are two ways to validate a form. First, perform validation as the user types. Second, performing validation after the user submits the...
Read more >
useForm - trigger - Simple React forms validation
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
Manually Triggering Form Validation using jQuery
It actually is possible to trigger validation manually. I'll use plain JavaScript in my answer to improve reusability, no jQuery is needed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found