PolymerElements / iron-form

Custom form element
https://www.webcomponents.org/element/PolymerElements/iron-form
63 stars 81 forks source link

Some input elements with `undefined` value will cause a Javascript error in `iron-request` #153

Open mercmobily opened 8 years ago

mercmobily commented 8 years ago

Description

A lot of elements (for example paper-textarea, but also paper-dropdown-menu) will have undefined as their value if the field is left untouched.

The serialize() method will create a record like this:

{
  line:"",
  multi: undefined
}

Which will make the method _wwwFormUrlEncodePiece() in iron-request fail with a Javascript error:

iron-request.html:431 Uncaught TypeError: Cannot read property 'toString' of undefined

Expected outcome

Those fields shouldn't be included in options.body

Actual outcome

Those fields are indeed included, making iron-ajax fail.

Live Demo

I don't have a live demo, but the code is dead simple:

<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/iron-form/iron-form.html">
<link rel="import" href="/bower_components/paper-input/paper-textarea.html">
<link rel="import" href="/bower_components/paper-input/paper-input.html">
<link rel="import" href="/bower_components/paper-button/paper-button.html">

<dom-module id="my-make-booking">
  <template>
    <style>
      :host {
        display: block;
      }
    </style>
    <form id="form" is="iron-form" action="/stores/bookings" method="post">
      <paper-input name="line"></paper-input>
      <paper-textarea name="multi" id="multi" label="Textarea label"></paper-textarea>
      <paper-button on-tap="_submit">Submit!</paper-button>
    </form>
  </template>
  <script>
    Polymer({
      _submit: function(){
        this.$.form.submit();
      },
      is: 'my-make-booking',
    });
  </script>
</dom-module>
mercmobily commented 8 years ago

I realise this is totally unpaid support etc. But I am totally stuck till I found a solution or a workaround. So... any help will be really, really welcome! (Even if it's a hint to direct me towards a workaround)

mercmobily commented 8 years ago

For what it's worth, I do have a workaround (I am monkey-patching iron-request). Thank you for reopening https://github.com/PolymerElements/iron-ajax/issues/214 !

H3dz commented 7 years ago

Looks like this is still not fixed.

For a simple workaround add a default value.

<paper-textarea value=""></paper-textarea>