Skip to content

checkValidity always returns true on readOnly forms #5931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
namti opened this issue Dec 1, 2024 · 9 comments
Closed

checkValidity always returns true on readOnly forms #5931

namti opened this issue Dec 1, 2024 · 9 comments
Assignees

Comments

@namti
Copy link

namti commented Dec 1, 2024

Describe the bug
checkValidity function always returns true on readOnly forms.

Version/Branch
4.15.1

To Reproduce
Steps to reproduce the behavior:

  1. Set form option readOnly to true
  2. Invoke checkValidity(submissionJson, true)
  3. If set readOnly to false, checkValidity returns false as expected

Expected behavior
Returns false on invalid forms even they are read only.

Additional context
Add any other context about the problem here.

@namti namti changed the title Options to validate readOnly forms checkValidity always returns true on readOnly forms Dec 1, 2024
@lane-formio
Copy link
Contributor

Have you checked this on later versions?
4.21.5 is our latest 4.x release
5.0.0-rc.100 is our most recent 5.x candidate (expecting to officially release within the next couple weeks)

@namti
Copy link
Author

namti commented Dec 2, 2024

Not yet. I am using @formio/[email protected] which is the latest version of it. The package uses formiojs@^4.15.1 as its dependency.

@namti
Copy link
Author

namti commented Dec 2, 2024

I have made an example using latest RC versions of @formio/react and @formio/js. The problem still exists.

https://stackblitz.com/edit/vitejs-vite-saq3bv?file=src%2FApp.jsx

@CaptainGlac1er
Copy link

"Constraint validation: If the readonly attribute is specified on an input element, the element is barred from constraint validation."

@formio formio deleted a comment from lane-formio Jan 22, 2025
@namti
Copy link
Author

namti commented Jan 28, 2025

"Constraint validation: If the readonly attribute is specified on an input element, the element is barred from constraint validation."

Since I manually invoke the checkValidity function to validate, can we have an option to forcibly validate the submission data irregardless of the read only option?

@lane-formio
Copy link
Contributor

After review, we don't expect to change or add any feature functionality around this behavior. We are always happy to review any contributions made but we won't be resourcing anyone for this.

@lane-formio lane-formio closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2025
@lane-formio
Copy link
Contributor

@namti
What is the use-case here that you would need to validate a read-only form?

@namti
Copy link
Author

namti commented Jan 30, 2025

@lane-formio We have multi-user collaborated forms. A user can occupy a form at one time. But all users can submit all forms. That requires validating read only forms.

Currently, I use a workaround solution.

const checkValidity = async (form: FormProps['form'], submission: FormProps['submission']): Promise<boolean | void> => {
  if(form){
    const el = document.createElement('div');

    let instance: any = null;

    await Formio.createForm(el, form)
      .then((form: any) => {
        form.submission = submission;
        instance = form;
      })
      .catch(err => console.error('Failed to initiate the form.', err));

    if(instance !== null){
      return instance.checkValidity(null, false);
    }
  }
};

This works but it costs performance.

@CaptainGlac1er
Copy link

@lane-formio I recommend not going away from the web standard. Angular FormControl works exactly the same way where validation is disabled on disabled fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants