DWR

DWRUtil.getValues return unnatural mapping when use on forms

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 2.0.rc5
  • Component/s: Util
  • Description:
    Hide

    invoking DWRUtil.getValues("someFormId") return a mapping with a strange choice of keys.
     
    A form, when submit using browser is a list of 'name=value' entries but DWRUtil does not take into account the name of elements. When you 'dump' a form using getValues you get a mapping in the form 'id=value' or, worse, if no id are defined, in the form 'value=value'.
     
    Looking at .js code i see what seems to me like a typo, as value=value in response is a nonsense:

    for (var i = 0; i < ele.elements.length; i++) {
      if (ele[i].id != null) value = ele[i].id;
      else if (ele[i].value != null) value = ele[i].value;
      else value = "element" + i;
      reply[value] = DWRUtil.getValue(ele[i]);
    }
     
    Unless this is corrected this make background sending of form a bit troublesome when you can't use the ids as key (because similar form is present several time in same webpage, i can't give to form element id=name, but i can afford dropping of the id)
     
    The line
      else if (ele[i].value != null) value = ele[i].value;
    should probably be
      else if (ele[i].name != null) value = ele[i].name;
     
    This way, each entry of resulting map is in the form (id or name or elementxyz)=value
    Show
    invoking DWRUtil.getValues("someFormId") return a mapping with a strange choice of keys.   A form, when submit using browser is a list of 'name=value' entries but DWRUtil does not take into account the name of elements. When you 'dump' a form using getValues you get a mapping in the form 'id=value' or, worse, if no id are defined, in the form 'value=value'.   Looking at .js code i see what seems to me like a typo, as value=value in response is a nonsense: for (var i = 0; i < ele.elements.length; i++) {   if (ele[i].id != null) value = ele[i].id;   else if (ele[i].value != null) value = ele[i].value;   else value = "element" + i;   reply[value] = DWRUtil.getValue(ele[i]); }   Unless this is corrected this make background sending of form a bit troublesome when you can't use the ids as key (because similar form is present several time in same webpage, i can't give to form element id=name, but i can afford dropping of the id)   The line   else if (ele[i].value != null) value = ele[i].value; should probably be   else if (ele[i].name != null) value = ele[i].name;   This way, each entry of resulting map is in the form (id or name or elementxyz)=value

Activity

Hide
Mike Wilson added a comment - 16/Apr/07 5:39 PM

Corrections are now checked in that first use
name=value
if name is set, or
id=value
if id is set, or last
elementX=value
if none of the above are set.

Show
Mike Wilson added a comment - 16/Apr/07 5:39 PM Corrections are now checked in that first use name=value if name is set, or id=value if id is set, or last elementX=value if none of the above are set.

People

Dates

  • Created:
    12/Apr/07 12:25 PM
    Updated:
    29/Feb/08 10:29 AM
    Resolved:
    16/Apr/07 7:52 PM