Skip to content
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

Failed validation reverts to last value in input field #1678

Closed
Reefcrazed opened this issue Sep 10, 2024 · 4 comments
Closed

Failed validation reverts to last value in input field #1678

Reefcrazed opened this issue Sep 10, 2024 · 4 comments

Comments

@Reefcrazed
Copy link

Reefcrazed commented Sep 10, 2024

Have you searched through other issues to see if your problem is already reported or has been fixed?

Yes, I did not find it.

Did you read the documentation?

Yes, I did not find it.

Have you tried to publish the views?

Yes - I didn't work.

Is there an error in the console?

No

PHP Version

8.3.9

PowerGrid

5.10

Laravel

11

Livewire

3.5.6

Alpine JS

3.14.1

Theme

Tailwind 3.x

Describe the bug.

Using EditOnClick for my fields, after any field fails to validate the original value stays in the field, not the value that actually failed. I would think the default value left would be what a user types in.

Example, there is a date field with a value of 09/10/2024 and I input 9/10/2024extradata and that field fails validation. The value sets as 9/10/2024 which is actually valid, but the field stays in an invalid state. If you go back into the field which still shows 9/10/2024 and hit enter it fails validation on the original value. This happens with other validation types, such as validating numbers. This is confusing to users because they are seeing a valid date in the field, other fields cannot be clicked in because of the still failed validation error. I notice the example project for validation acts the same way.

On the example project for validation, if you put in an invalid flavor it will fail validation but vanilla will be the default, if you click back in the input where it says vanilla and hit enter it still fails validation. You literally have to back over the word and retype it for it to pass.

Capture

validation

To Reproduce...

Simple project with validation, fail a validation and the default value left in the input will be the original value, not what was typed. This seems to be how the example validation project also works.

Extra information

<?php
 //...
@Uhasith
Copy link

Uhasith commented Sep 11, 2024

We’re encountering the same issue. If validation fails and we press the Esc button to reset the field, the error message persists. As a result, we are unable to edit or select a different column for editing, which makes it feel buggy

@Uhasith
Copy link

Uhasith commented Sep 18, 2024

After triggering any validation, we cannot press the esc key to edit a different field. The live demo also has this glitch.

Live Demo

@luanfreitasdev
Copy link
Collaborator

Fixed on 6x: #1712

Thank you

@luanfreitasdev
Copy link
Collaborator

Update:

 $this->withValidator(function (\Illuminate\Validation\Validator $validator) use ($id, $field) {
      if ($validator->errors()->isNotEmpty()) {
          $this->dispatch('toggle-'.$field.'-'.$id); // if there is an error, this makes the input enable editing again
      }
  })->validate();

Demo: https://demo.livewire-powergrid.com/examples/validation

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

3 participants