AjaxControlToolkit icon indicating copy to clipboard operation
AjaxControlToolkit copied to clipboard

ComboBox: Validation fails when empty

Open kevinoid opened this issue 3 years ago • 0 comments

The AJAX Control Toolkit 20.1.0

The installation method

  • [ ] Installer
  • [x] NuGet package
  • [ ] A custom build from the source code

Minimal steps to reproduce the bug

Add a validator control (e.g. RegularExpressionValidator) to a ComboBox. Attempt to submit the form, leaving the ComboBox empty.

Actual result

Validation fails and the form is not submitted.

Expected result

The form would be submitted without error, as it would be if ComboBox were replaced with TextBox.

Browser(s) used

  • Edge 85.0.564.51
  • Firefox 80.0.1
  • Internet Explorer 11

A site deployment method

  • [x] VS development web-server,
  • [ ] IIS

Sample project: https://gist.github.com/kevinoid/6f3773ed5ea51e43b6cafed2da3f75e9

Discussion

The error only occurs client-side and can be avoided by setting EnableClientScript=false on the validator. The error occurs because the ValidatorGetValueRecursive function (basically) returns the first non-empty value from an input element. When the text input is empty, it returns the value from the HiddenField with the selected index (-1 when empty).

I'd suggest setting the HiddenField to the empty string, rather than -1, when a value is not selected to avoid the issue.

Thanks for considering, Kevin

kevinoid avatar Sep 15 '20 23:09 kevinoid