DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG� RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=32343>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND� INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=32343 ------- Additional Comments From [EMAIL PROTECTED] 2004-12-02 14:40 ------- Hi Niall, I see what you mean with the focus. There is a little trick we can use for this and it's javascript's eval function. If we change the method grabValuesFromField(oField) to validateField(oField, validatorFunction) then we can apply the validations programatically in each iteration. We have to make some minor changes for grabValuesFromSingleField which considers the radio or checkbox fields an array of fields even when there is only one. For this, we have to make a "virtual field" for the case when there is only one radio button and convert it to a single element array of radios. Please do take a look at http://www.visual-ma.com/validator/grab.html as it has the modified page. You can choose the validation (currently there are only 2 validations: integer and required) and validate on each field. BTW, do you think I should post this on a separate bug as an enhancement? function validateRequired(values) { var isValid = values.length > 0; for (i=0; i<values.length; i++) { if (trim(values[i]).length == 0) { isValid = false; break; } } return isValid; } function validateInteger(values) { var isValid = true; for (i=0; i<values.length; i++) { if (!isAllDigits(values[i])) { isValid = false; break; } else { var iValue = parseInt(values[i]); if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) { isValid = false; break; } } } return isValid; } (I am not putting the side functions (eg: isAllDigits, trim) for clarity) function validateField(oField, validatorFunction) { if (!oField.type && oField.length && oField[0]) { //if it has no type it means there are multiple fields with the same name. We shall put the type //for the field for easier handling oField.type = oField[0].type; oField.name = oField[0].name } var bValid = true; var focusField = oField; if (oField.type == 'radio' || oField.type == 'checkbox') { var virtualField = oField; if (!oField.length) { virtualField = new Array(); virtualField.type = oField.type; virtualField.name = oField.name; virtualField[0] = oField; } eval("bValid = " + validatorFunction + "(grabValuesFromSingleField(virtualField))"); //no need to focus on these focusField = null; } else if (oField.length && !oField.options) { for (n=oField.length - 1; n>=0; n--) {//reverse so we can focus on the first eval("var auxValid = " + validatorFunction + "(grabValuesFromSingleField(oField[n]))"); if (!auxValid) { //if it's not valid for a single element it won't be valid bValid = auxValid; focusField = oField[n]; } } } else { eval("bValid = " + validatorFunction + "(grabValuesFromSingleField(oField))"); } if (!bValid && focusField && focusField.focus && focusField.style.visibility != 'hidden' && focusField.disabled == false && focusField.type != 'hidden') { focusField.focus(); } } function grabValuesFromSingleField(oSingleField) { var singleValues = new Array(); if (oSingleField.type == 'select-multiple') { for (s=0; s<oSingleField.options.length; s++) { if (oSingleField.options[s].selected) { singleValues[singleValues.length] = oSingleField.options[s].value; } } } else if (oSingleField.type == 'select-one') { singleValues[0] = oSingleField.options[oSingleField.selectedIndex].value; } else if (oSingleField.type == 'radio' || oSingleField.type == 'checkbox') { for (s=0; s<oSingleField.length; s++) { if (oSingleField[s].checked) { singleValues[singleValues.length] = oSingleField[s].value; } } } else { singleValues[0] = oSingleField.value; } return singleValues; } -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
