Title: Editwizards hack to validate option lists

Hello
I made a small hack to validate optionlists. The _javascript_ that checks the value of a mandatory field takes the index number of the selected option as value if the input type is a oplist, so this is allways true.

I made the code check for the input type, and if it is an 'select-one' type, i read the value of the selectd option.
Now you can add an option like:
<option id="">-choose an option</option>
To your optionlist, and validation works ok.
Jaco argued that perhaps the xsl should be changed to allways add an extra empty option if dtrequired="true", but this might give backwards compatibility issues, and is less flexible (what if you want to have a default option at the top of the list?). On the other hand this would be more understandable behavour and dous not require specific documentation.

Should this be added to the code??

ernst

Validator.js:
---------------------------------------------
Validator.prototype.validateElement = function (el, silent) {
    var err = "";
    var v = getValue(el);
                if(el.type =="select-one"){
                        v=(el.options.item(v).value);
                }

    dtpattern = el.getAttribute("dtpattern");
    if (!isEmpty(dtpattern)) {
        var re = new RegExp(dtpattern);
        if (!v.match(re)) {
           err += getToolTipValue(form,'message_pattern', "the value {0} does not match the required pattern", v);
        }
    }
---------------------------------------------

Reply via email to