I’m having a problem with some odd listbox validation when used on a form.
The issue is that I have one set of dependent dropdown’s that work fine, both are mapped to Varchar data by the model.
The second set of drop downs are mapped to Integer fields.
Both of the dependent dropdowns are disabled until the the parent dropdown has a selection.
On form validate IF the child of the Varchar mapped dropdown is not selected it validates and Yii does it’s magic with the error indicators being set (text and field background color)
However the child of the dropdown that is mapped to the integer field in the model does not show as an error for being empty.
What’s odd is that this is only the case on entry to the page, for example if I come in fresh to the page and just hit submit, all fields are empty and show up as error conditions EXCEPT the one dependent listbox that is mapped to an integer field.
Last test was on the listbox for the integer field that doesn’t seem to validate was to make it enabled. At that point it works and shows the error conditions from not being set.
It seems that if the field type is Integer, and the dropdown is DISABLED the validation does not happen? Anyone else run into odd things like this?
Sorry for the complex description, hope it’s understandable!
I think that is the gist of the problem. The db table has a default value of ‘0’ for the integer fields, and and empty string (not a null) for the character fields. The operations for the disabled integer dropdown may be the correct operation, but the odd part is trying to make both of the dropdown behave the same irrespective of datatype. Both have the same and single entry into the listbox options html which is something like this -
// for the int field
<option value="">Select Model</option>
// for the varchar field
<option value="">Select City</option>
In some testing I found when I removed the listbox and just put up a simple text field the value initially was 0 (zero), which really didn’t shock me. I guess for the integer field it has a value of something which is in this case 0 and the validation rule is numeric and required so it can never be wrong. I think the solution to make it match the validation would be to come up with a rule that says NOT ZERO. I had made a conscious effort to not use a value of 0 for this type of data and I think it may pay off as I can validate that as a special case I guess, just need to read more on how to do that, and given how Yii seems to work it’s likely very simple