PolymerElements / iron-ajax

Easily make ajax requests
https://www.webcomponents.org/element/PolymerElements/iron-ajax
127 stars 113 forks source link

the iron-request element crash when attribute in body object value is null #214

Closed jperera84 closed 7 years ago

jperera84 commented 8 years ago

Description

I'm running in a issue with iron-ajax element, the problem is that I have an object "company" that has a few attributes but some of them can be empty (null). I'm trying to run an update of that Object to the database:

<iron-ajax
            verbose
        url="https://signasafeapi.azurewebsites.net/api/Companies/{{company.Id}}"
        method='PUT'
      body="{{company}}"
        handle-as="json"
      headers='{"Authorization": "Bearer {{sessionObject.access_token}}"}'
        content-type="application/x-www-form-urlencoded"
        on-response="handleSubmitCompany"
        debounce-duration="300"
      on-error = 'handleSubmitCompanyError'
        id='daoSubmitCompany'>
        </iron-ajax>

Expected outcome

Send the request to the Server.

Actual outcome

iron-request crash:

  /**
     * @param {*} str A key or value to encode as x-www-form-urlencoded.
     * @return {string} .
     */
    _wwwFormUrlEncodePiece: function(str) {
      // Spec says to normalize newlines to \r\n and replace %20 spaces with +.
      // jQuery does this as well, so this is likely to be widely compatible.
      return encodeURIComponent(str.toString().replace(/\r?\n/g, '\r\n'))
          .replace(/%20/g, '+');
    },

iron-request.html:424 Uncaught TypeError: Cannot read property 'toString' of null

Steps to reproduce

  1. Create an object "Company".
  2. Assign values to the non null attributes.
  3. Let come attributes empties.
  4. Execute this.$.daoSubmitCompany.generateRequest()

    Browsers Affected

mercmobily commented 8 years ago

It looks like some elements (paper-textarea, but also paper-dropdown-menu for example) leave the field as undefined if it was untouched by the user. This causes a very similar error...

See: https://github.com/PolymerElements/iron-form/issues/153

e111077 commented 8 years ago

@mercmobily I have a PR awaiting team review at #234

mercmobily commented 7 years ago

Was this forward-ported to Polymer 2? I am running a monkey-patched version of Polymer to get around it, and am planning on porting my app to P2...

On 27 May 2017 at 09:29, Elliott Marquez notifications@github.com wrote:

Closed #214 https://github.com/PolymerElements/iron-ajax/issues/214 via

234 https://github.com/PolymerElements/iron-ajax/pull/234.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PolymerElements/iron-ajax/issues/214#event-1099731588, or mute the thread https://github.com/notifications/unsubscribe-auth/ACB7Xt1xp1ff11Loq_6agOpwBlyBqSuuks5r93x6gaJpZM4JEd1o .