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.

'this.form.clearErrors()' returns error

See original GitHub issue

Versions:

  • @inertiajs/inertia version: 0.8.4
  • @inertiajs/inertia-vue version: 0.5.5
  • @inertiajs/inertia-vue3 version: 0.2.3
  • @inertiajs/inertia-react version: -
  • @inertiajs/inertia-svelte version: -

Describe the problem:

Context:

The form is initialized like so:

data () {
    return {
        form: this.$inertia.form({
            '_method': 'PUT',
            name: '',
        }, {
            bag: 'updateDivisionForm'
        }),
    }
},

The problem:

Whenever I call this.form.clearErrors() the errors are not cleared and the console returns an error: Screenshot_136

I have already ran yarn upgarde --latest.

Steps to reproduce:

  1. Create the form using form: this.$inertia.form({...}) with errorbag (like in example above)
  2. Submit the form using this.form.post()
  3. (optional) Have the server return a validation error
  4. Call this.form.clearErrors()

Did I miss something? I used these docs as guide


Issue Analytics

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

github_iconTop GitHub Comments

2reactions
timyourivhcommented, Jan 26, 2021

@claudiodekker Good observation!

The application I’m working on was originally a laravel jetstream project but we decided to replace jetstream with just inertia and vuetify. I did now know the jetstream package was overwriting the default inertia forms. I uninstalled the jetstream package (since this was still installed and enabled 🤦). And converted the forms as you suggested and that fixed my issue!

Hooray! Now I can use it! Thanks for the quick response!

2reactions
claudiodekkercommented, Jan 26, 2021

Hi @TimVanHerwijnen,

Are you sure you don’t have jetstream-js installed into your package.json & JS assets by any chance? This was something that was automatically being used in Laravel Jetstream 1.x, but was removed entirely in Laravel Jetstream 2.x in favor of the form helper that ships with Inertia out of the box nowadays.

Assuming this is the case, this perfectly explains why you’re seeing the error that you do: When Jetstream 1.x shipped and Inertia didn’t have a form helper of it’s own, jetstream-js “patched” a form method onto the $inertia object, and while this was great for Jetstream & Inertia users at the time, it now also causes the natively supported/documented Inertia form helper (the one you’re clearly trying to use) to be overwritten.

The reason for this question / assumption has to do with the way I’m seeing you define your form helper. The following two lines were only used with jetstream-js’s form helper, and don’t actually do anything with Inertia’s native form helper:

        form: this.$inertia.form({
            '_method': 'POST',
            name: '',
            selectedNumbers: [],
-        }, {
-            bag: 'createDivisionForm'
        }),

Anyway, removing this jetstream-js dependency and migrating to Inertia’s form helper shouldn’t be too difficult for any of the existing (jetstream) $inertia.form’s you might have, as the API’s are very similar.

Hope this helps! 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

useForm - ClearErrors - React Hook Form
This function can manually clear errors in the form. Props. Type, Description, Example. undefined, Remove all errors. clearErrors().
Read more >
React Hook Form - Set Error / Clear Error - CodeSandbox
VS Code's tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code. Manage Extension.
Read more >
public function FormState::clearErrors - Drupal 8.2.x
Clears all errors against all form elements made by self::setErrorByName(). Overrides FormStateInterface::clearErrors. File. core/lib/Drupal/Core/Form/FormState ...
Read more >
Blog - New in Symfony 4.2: Clear form errors
Symfony 4.2 adds a new clearErrors() method to allow you remove errors after the form has been validated.
Read more >
How to clear errors object in vee-validate? - vue.js
I have come up with another solution that could help. in your input we'll add another listener so it will be like this:...
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