Welcome Guest, Not a member yet? Register   Sign In
form_dropdown selected issue screwing with validation and jquery
#1

[eluser]coolgeek[/eluser]
I'm having a problem with default (selected) options in forms, but I don't think that the problem lies with form_dropdown.

My observations have shown that failing to specify the third parameter will default to the first option marked up as "selected" in the html (note that this should probably be specified in the user guide):

Code:
form_dropdown('state', $options)

and specifying the third parameter as null generates the desired html (no "selected" option)

Code:
form_dropdown('state', $options, '')

However, even though the html shows no option as selected, the form validation functions and jquery seem to think otherwise.

- the validation 'required' parameter is not recognizing that no option was selected
- jquery is taking action as if an option was selected at $(document).ready

FWIW, I am in fact specifying a fourth parameter, as follows:

Code:
$js = "id=\"state\" class=\"\"";
echo form_dropdown("state", $options, '', $js);

Also, somewhat related (rather than starting a separate thread), I'm trying to put all of my dropdown population functions in an extended form helper. So far, so good, but I'm also putting a validation callback in the helper, and I'm having a problem trying to use the form_validation set_message function. Is this not possible because helpers are procedural, rather than object oriented? If it is possible, can somebody give me a hint here?

Thanks for your assistance
#2

[eluser]symbol.software[/eluser]
I am facing the same problem with form validation not recognizing that no option was selected in the dropdown menu.. Is this a CI bug ?

Thanks
#3

[eluser]coolgeek[/eluser]
I ended up looking at the W3C spec

Quote:If no OPTION element has the selected attribute set, user agent behavior for choosing which option is initially selected is undefined.

As such, whether or not this is a "bug" in CI form validation is moot. I ended up passing a zero option as selected to all of my dropdowns, and checking the value with a validation callback. If it is zero, the user didn't engage the dropdown to select a value
#4

[eluser]symbol.software[/eluser]
[quote author="coolgeek" date="1253828179"]I ended up looking at the W3C spec

Quote:If no OPTION element has the selected attribute set, user agent behavior for choosing which option is initially selected is undefined.

As such, whether or not this is a "bug" in CI form validation is moot. I ended up passing a zero option as selected to all of my dropdowns, and checking the value with a validation callback. If it is zero, the user didn't engage the dropdown to select a value[/quote]

Found the same solution too.




Theme © iAndrew 2016 - Forum software by © MyBB