Hi I used jquery validation engine for form controls validation purpose. It works well at all controls. But It is partially worked on listbox control. I used 2 listboxes in my form. Because I
provide user to choose more than one options and remove users options. For this purpose I used 2 lisboxes. User can select options in the first listbox and pass to second listbox. Actally
listbox validation is needed on second listbox. Second listbox options are needed to submit. I also provide max list options to 5. It works well. I also added required field validation to
second listbox. But It does not work well. every time I needed to select min one option when I submit options. If not any option select in the second listbox then the required field validation
error is fired. I didnt understand why the required field is fired when the data is occured in the second listbox. I am new to jquery.
My code is below.
aspx code:
<asp:ListBox ID="lstStudentSelectedSubjects" runat="server" Width="180px"
Height="120px" SelectionMode="Multiple" class="validate[required,maxList[5]]" ></asp:ListBox>
jquery validation engine code:
case "maxList":
errorMsg = methods._maxList(field, rules, i, options);
field = $($("select[name='" + fieldName + "']"));
break;
_maxList: function (field, rules, i, options) {
var listItems = rules[i + 1];
var groupname = field.attr("name");
var groupSize = $("select[name='" + groupname + "'] option").size();
//alert("HI" + groupSize);
if (groupSize > listItems) {
var rule = options.allrules.maxList;
return rule.alertText + listItems + rule.alertText2;
}
},
"maxList": {
"regex": "none",
"alertText": "* Select max ",
"alertText2": " subjects only"
},