Tapestry
  1. Tapestry
  2. TAPESTRY-1107

Required Field validation behavior changed between 4.0 and 4.1.1

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.1
    • Fix Version/s: 4.1.1
    • Component/s: JavaScript
    • Labels:
      None

      Description

      In 4.0, a Select list with a selection with an empty value failed the required field validation. In 4.1.1, if any item is selected it is valid, even if that item has no value.

      The old behavior worked with Java validation, the new one does not - a selection with a null/empty value submits null, which fails server-side validation.

      The problem is in dojo.validate.check() line 100 in the current snapshot.

      Since this is in Dojo, that behavior may be the desired default, but Tapestry needs a modified behavior with an additional condition - if the element is a select-one or select-multiple, if it has a selection that selection (or at least one of the selections) must not have an empty value.

        Activity

        Hide
        Jesse Kuhnert added a comment -

        Fixed in dojo && tapestry now.

        Show
        Jesse Kuhnert added a comment - Fixed in dojo && tapestry now.
        Hide
        Jesse Kuhnert added a comment -

        Change can be tracked here:

        http://trac.dojotoolkit.org/ticket/1615

        Show
        Jesse Kuhnert added a comment - Change can be tracked here: http://trac.dojotoolkit.org/ticket/1615
        Hide
        Greg Woolsey added a comment -

        One possible solution - here is a solution inside an updated If statement for required fields for context:

        // See if required input fields have values missing.
        if ( profile.required instanceof Array ) {
        for (var i = 0; i < profile.required.length; i++) {
        if(!dojo.lang.isString(profile.required[i]))

        { continue; }

        var elem = form[profile.required[i]];
        // Are textbox, textarea, or password fields blank.
        if ( (elem.type == "text" || elem.type == "textarea" || elem.type == "password") && /^\s*$/.test(elem.value) )

        { missing[missing.length] = elem.name; }

        // Does drop-down box have option selected.
        else if ( (elem.type == "select-one" || elem.type == "select-multiple") ) {
        if (elem.selectedIndex == -1 )

        { missing[missing.length] = elem.name; }

        else {
        var isMissing = true;
        for (var j = 0; j < elem.options.length; j++) {
        if (elem.options[j].selected && ! (/^\s*$/.test(elem.options[j].value)) )

        { isMissing = false; break; }

        }
        if (isMissing) missing[missing.length] = elem.name;
        }
        }
        // Does radio button group (or check box group) have option checked.
        else if ( elem instanceof Array ) {
        var checked = false;
        for (var j = 0; j < elem.length; j++) {
        if (elem[j].checked)

        { checked = true; }

        }
        if ( !checked )

        { missing[missing.length] = elem[0].name; }

        }
        }
        }

        Show
        Greg Woolsey added a comment - One possible solution - here is a solution inside an updated If statement for required fields for context: // See if required input fields have values missing. if ( profile.required instanceof Array ) { for (var i = 0; i < profile.required.length; i++) { if(!dojo.lang.isString(profile.required [i] )) { continue; } var elem = form[profile.required [i] ]; // Are textbox, textarea, or password fields blank. if ( (elem.type == "text" || elem.type == "textarea" || elem.type == "password") && /^\s*$/.test(elem.value) ) { missing[missing.length] = elem.name; } // Does drop-down box have option selected. else if ( (elem.type == "select-one" || elem.type == "select-multiple") ) { if (elem.selectedIndex == -1 ) { missing[missing.length] = elem.name; } else { var isMissing = true; for (var j = 0; j < elem.options.length; j++) { if (elem.options [j] .selected && ! (/^\s*$/.test(elem.options [j] .value)) ) { isMissing = false; break; } } if (isMissing) missing [missing.length] = elem.name; } } // Does radio button group (or check box group) have option checked. else if ( elem instanceof Array ) { var checked = false; for (var j = 0; j < elem.length; j++) { if (elem [j] .checked) { checked = true; } } if ( !checked ) { missing[missing.length] = elem[0].name; } } } }

          People

          • Assignee:
            Jesse Kuhnert
            Reporter:
            Greg Woolsey
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development