Blazorise icon indicating copy to clipboard operation
Blazorise copied to clipboard

[Bug]: Autocomplete validation within DataGrid appears to not work

Open leetheman opened this issue 2 years ago • 9 comments

Blazorise Version

1.4

What Blazorise provider are you running on?

Bootstrap5

Link to minimal reproduction, or a simple code snippet

I'm in an Edit template. The below works and validates (I'm using UseValidation="true")

<Validation Validator="ValidationRule.IsNotEmpty" >
   <TextEdit @bind-Value="swe"></TextEdit>
</Validation>

But the below does not... it doesn't seem to use the validation at all. The ValueField is an Int32 if that helps?

Steps to reproduce

(not sure why but it's stripipng out the validation tags when I post this, however, it's the autocomplete wrapped in a validation tag) <Validation Validator="ValidationRule.IsNotEmpty" ><Autocomplete Data="Clients" Filter="AutocompleteFilter.Contains" HighlightSearch="true" FreeTyping="false" MinLength="0" @bind-SelectedValue="@context.CellValue" Placeholder="Select client..." TextField="x => x.Name" ValueField="x => x.Id"/></Validation>"

What is expected?

hoping the autocomplete would get validated too

What is actually happening?

the autocomplete is not validated and the Grid attempts to save, resulting in an error

What browsers are you seeing the problem on?

Chrome

Any additional comments?

The Field for the DataGridColumn is bound to an Int32

leetheman avatar Jan 17 '24 17:01 leetheman

I think that ValidationRule if reserved for actual empty strings. You will need to provide your own ValidationRule that checks ints. image

https://blazorise.com/docs/components/validation

The first example shows a method an implementation of a custom validation named ValidateEmail

David-Moreira avatar Jan 17 '24 17:01 David-Moreira

Thanks, I got around it using:

 <Autocomplete Validator="_ => _.Status = Convert.ToInt32(context.CellValue) > 0 ? ValidationStatus.Success : ValidationStatus.Error "

Is that "best practice" do you think? seems to work, only hitch is that once I do select a valid value, the outline remains red (even though it is now valid). Let me know if there's a better way to do this :-)

leetheman avatar Jan 17 '24 17:01 leetheman

I would personally recommend doing something similar to our ValidationRule class to centralize, reuse your validators instead of binding an anonymous delegate.

But at the end of the day, it's up to you, and your project.

If it's not validating correctly then that might be a bug. We'll take a look as soon as possible.

David-Moreira avatar Jan 17 '24 17:01 David-Moreira

No problem, yes I have moved it into a validation service. All looks well, although it does not revalidate if I select a value, still claims it's empty

I've recorded a GIF: Animation

In the second half of the gif, you can see another problem, unsure if it's the autocomplete or validation. Basically I have 3 "lee ramsingh" entries, with Ids of 38, 41 and 42. The autocomplete only lets me select the first one? If I try the other 2 they disappear as you can see at the end of the GIF. Any ideas?

leetheman avatar Jan 17 '24 18:01 leetheman

Further to this, if I change the names so they are unique, the autocomplete works. Is there a bug if there are duplicate text despite the Ids being different?

leetheman avatar Jan 17 '24 18:01 leetheman

context

Currently we tie the text and value to an item. So there isn't exactly a correlation between the text and value, they are correlated by the item itself. So currently both need to be unique.

As for the issue with validation can you provide a repro please?

David-Moreira avatar Jan 23 '24 21:01 David-Moreira

Hello @leetheman, thank you for your submission. The issue was labeled "Status: Repro Missing", as you have not provided a way to reproduce the issue quickly. Most problems already solve themselves when isolated, but we would like you to provide us with a reproducible code to make it easier to investigate a possible bug.

github-actions[bot] avatar Jan 23 '24 21:01 github-actions[bot]

Hi there, please see attached:

https://github.com/leetheman/BlazoriseAutocompleteRepro

Validation is sorted now thanks;

in the repro I have two grids with the following source data:

Id Name Display Name 1 Client A "1 - Client A" 2 Client A "2 - Client A" 3 Client B "3 - Client A"

The first one uses the Text field of "Name", which means there are duplicate entries in the dropdown. The buggy behaviour is that if you select the first one, it works fine, but if you select the second or third, it just blanks out.

I appreciate that in real life, this scenario should not happen, but you never know what a client might do and then complain that the system is broken. Ideally if they chose the second option in the list, it would select "2" as the ID, and the third option would be "3".

Hope this helps, happy to spin up more examples if needed.

leetheman avatar Jan 24 '24 02:01 leetheman

Hello @leetheman

I guess It does make sense, that it shouldn't break on repeated texts. Autocomplete was developed like this, so we need to take careful look when changing it to make sure we break nothing else.

For now, I can only advise a workaround, to do some pre initialization of the data where you go find the duplicates and make them different texts somehow, something like :

  • add blank spaces "Client A", "Client A ", "Client A "
  • add numbers like Client A (1), Client A (2), Client A (3)

David-Moreira avatar Jan 24 '24 09:01 David-Moreira

I'm closing this issue and opening a new one, where the scope will be to investigate Autocomplete & supporting repeated texts.

David-Moreira avatar Mar 09 '24 11:03 David-Moreira