Ilhasoft / data-binding-validator

Android fields validation library based on data binding adapters.
Apache License 2.0
344 stars 53 forks source link

Validate androidx.appcompat.widget.AppCompatSpinner #38

Open xjpmauricio opened 4 years ago

xjpmauricio commented 4 years ago

How can I validate a Spinner? I tried adding one of the validations but I get this compilation error:

Cannot find a setter for <androidx.appcompat.widget.AppCompatSpinner app:validateMinLength> that accepts parameter type 'int' If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches

danielsanfr commented 4 years ago

Would it be a validation of the quantity of items in Spinner?

xjpmauricio commented 4 years ago

Yes, if the spinner has no items.

Another improvement would be to validate if the user has selected an item in the spinner other than the first, where usually we place the text "Please select an item" that usually has no value.

danielsanfr commented 4 years ago

So, the quantity of items in a Spinner doesn't seem to be interesting to add to that library.

Now checking if another item, other than the first one, was selected seems to be very interesting! But for that case, we would have to use a Toast. Since Spinner does not have a setError() method like EditText and TextInputLayout.

If you want to contribute, we can analyze the PR. If not, maybe I'll find some time to do this later.

xjpmauricio commented 4 years ago

On the spinner, you can do the setError on the TextView it contains. The only problem is if the spinner has no items it will not have the TextView. My initial need was for a validation on the number of items on the spinner; sometimes if you select a parent spinner the child spinner will have no items. It would be nice to have.

You could do also another improvement that I've seen on other web validation libraries which is create a error placeholder that would be placed under the widget being validated.