DevExpress / AjaxControlToolkit

The ASP.NET AJAX Control Toolkit is a classic set of ASP.NET WebForms extensions.
https://devexpress.com/act
BSD 3-Clause "New" or "Revised" License
287 stars 135 forks source link

ComboBox: Validation fails when empty #556

Open kevinoid opened 4 years ago

kevinoid commented 4 years ago

The AJAX Control Toolkit 20.1.0

The installation method

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

A site deployment method

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