[jQuery validate] Issue with wrong widgets being validated
Hi,
I have the following structure using jQuery validate from bassistance.de:
html:
- <form>
-
<input
|
|
type="text" |
|
name="object[attr][fname][value]" |
|
id="object[attr][fname][value]" |
|
size="25" |
|
|
|
class="fx-widget fx-validate" |
|
data-validation='[{"MESSAGE":"Required Field","TYPE":"required"},{"MESSAGE":"Minimaal 2 karakters vereist","TYPE":"minlength","LENGTH":"2"}]' |
|
/>
| <select |
|
name="object[attr][language][value]" |
|
id="[comboboxwidget_language][value]" |
|
size="1" class="fx-widget"
|
|
data-validation='[]' |
|
> <option |
|
name="[comboboxwidget_language][CBO_SELECTOR]" |
|
id="[comboboxwidget_language][CBO_SELECTOR]" |
|
value="" |
|
> |
|
Please select... |
|
</option> |
|
<option |
|
name="[comboboxwidget_language][nl]" |
|
id="[comboboxwidget_language][nl]" |
|
value="nl" |
|
> |
|
Dutch |
|
</option> |
|
<option |
|
name="[comboboxwidget_language][en]" |
|
id="[comboboxwidget_language][en]" |
|
selected="selected" |
|
value="en" |
|
> |
|
English |
|
</option> |
|
<option |
|
name="[comboboxwidget_language][fr]" |
|
id="[comboboxwidget_language][fr]" |
|
value="fr" |
|
> |
|
French |
|
</option> |
|
<option |
|
name="[comboboxwidget_language][de]" |
|
id="[comboboxwidget_language][de]" |
|
value="de" |
|
> |
|
German |
|
</option> |
|
</select> |
|
My javascript initialises all widgets which require validations as follows:
- // let's add form validation...
- $('form').livequery(function() {
- $(this).validate();
- $(this).find('.fx-widget').each(function() {
- validators = $.parseJSON($(this).attr("data-validation"));
- for(i = 0; i < validators.length; i++) {
- switch(validators[i]["TYPE"]) {
- case 'required':
- $(this).rules("add", {
- required: true,
- messages: {
- required: validators[i]["MESSAGE"]
- }
- });
- break;
- case 'minlength':
- $(this).rules("add", {
- minlength: validators[i]["LENGTH"],
- messages: {
- required: validators[i]["MESSAGE"]
- }
- });
- break;
- case 'maxlength':
- $(this).rules("add", {
- maxlength: validators[i]["LENGTH"],
- messages: {
- required: validators[i]["MESSAGE"]
- }
- });
- break;
- default:
- // do nothing...
- }
-
- }
- });
- });
As you can see, for all widgets in a form, we check for the data-validation json string, parse it and dynamically add validators to the widgets.
This works fine, but in the above example, whenever we loose focus on the combobox, it validates saying that you need to enter two characters at least... I don't understand why it does...
Does anyone else have an idea?
If you want, I can create a public example... Just let me know...
---
http://www.flexin.be