[BUG] checkValidity() not validating required fields.
checkValidity() isn't working anymore. We depend on this to manipulate data and validate it. It was working fine when I first implemented it a while back and I just realized that there are a bunch of invalid data going through because the checkValidity function has only been returning true for a while now. I am also calling the setPristine function before checkValidity. This is a massive issue, please help!!!
@formio/angular: 5.2.2 formiojs: 4.14.1
Saw the other issue reported before, https://github.com/formio/formio.js/issues/1352. So, I've tried setPristine(false) before doing the checkValidity() as well. Sometimes it works, sometimes it doesn't. We need to be able to check the form manually before the user enters the form. We've got required fields as well. checkValidity() seems buggy so we can't rely on this method. Is there another alternative?
formiojs: 4.13.8 ReactJS: 17.0.2
@randallknutson @travist , is this something you guys are aware of? And is there any alternative solution we can use to simply do a validation check without submitting the form?
Hi, @rubandangol @sthammav could you send any console errors screenshots or steps to reproduce this issue?
So I've tried using just the Javascript SDK + JSFiddle - https://jsfiddle.net/sthammav/y4r53Lzt/64/ . On initial load, in the on form change event, if you don't type anything, the isValid flag is true. Which seems wrong. It should be false. I haven't entered anything in the form yet. So we couldn't rely on the on form change event.
So I was using the checkValidity() to manually check the form is valid on load (no user input yet). I was trying to figure out an event to capture the manual check if the form is valid when you don't type anything on required field forms so I've put in the on blur event.
In our code in ReactJS, if the state changes, this function checkValidity() works and sometimes doesn't work. I can't seem to reproduce it though using the codesandbox. So I'm still working on the code sample.
But for the issue above in the form on change event, we can't rely on the isValid flag.

@sthammav could you try to setPristine to false and then redraw the form instance?
form.ready.then(() => {
form.setPristine(false);
console.log('Form is ready');
form.redraw();
});
@edwinanciani That didn't work.. Tried it and the console log says the form is valid on load when it shouldn't be. https://jsfiddle.net/sthammav/y4r53Lzt/67/

@sthammav it seems there is a change event when the default values are triggered. I have tried this. But I still do not understand the use case for this implementation could you give me a little more information on that. https://jsfiddle.net/edwinanciani/x1e9fjcq/
@edwinanciani The use case is that we want to keep track of the state of whether the user has filled out all the required fields in the form, in ReactJS, before the user can continue to the next step. We need to capture more data besides the formIO forms. As you can tell, we aren't using the submit button. So the onFormChange method, isValid flag is giving a false state on the first form change event. So we switch to using the checkValidity method. And we've found out that method is buggy. I'm not sure if it's a browser/Chrome issue or not.
@rubandangol Did you notice if the bug in checkValidity happened on certain browsers? I've updated my Chrome browser and not able to reproduce it.
@sthammav And for this use case this code is not working for you?
form.ready.then(() => {
form.setPristine(false);
form.checkValidity();
form.redraw();
console.log('Form is ready');
});
Hi, representing a client that wants to see this issue fixed. I am assessing the options to do this the right way, before we do anything less optional:
- Is this a regression? (The feature has worked in past versions, but no longer. I.e it is a "bug", and not a "feature request")
- Is there a test framework that supports/confirms this?
- Is there anybody currently working on this (so we don't duplicate efforts)
- Anything I need to know with respect to sending pull requests and licensing? (Basically that the contributor doesn't need to sign a CLA - Contributor License Agreement)
Regards, Niklas
Closing this thread as it is outdated. Please re-open if it is still relevant. Thank you for your contribution!