Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get response from an iron-form Polymer 1 request

i'm trying to get the response from an iron-form in Polymer 1.

Form submit call a php script which return HTML code to insert in a div (ul and some li).

I use the iron-form event "iron-form-response" but i don't know how to get the response.

I can see the response in network tab of browser developer tools, but don't know how to get it in my element.

I don't find how to do in the iron-form documentation online.

Can someone help me please ?

like image 287
krazitchek Avatar asked Jul 06 '15 16:07

krazitchek


2 Answers

What's happening, guys? All these responses confuse the OP when it is only this simple:

Your form:

<form is="iron-form" on-iron-form-response="responseHandler" action="http://localhost" id="myform">
   <!-- Your form elements -->
</form>

Your script:

<script>
   Polymer({
       // Some scripts here.

       // ...now your listener
       responseHandler: function(e) {
          console.log(e.detail.response);
       },                          
   });
</script>

It's just that. Nothing complicated. Don't over-complicate things.

like image 57
Jhourlad Estrella Avatar answered Nov 16 '22 19:11

Jhourlad Estrella


Add Event Listeners to iron form.

ready: function(){
      this.$.myform.addEventListener('iron-form-response',this.formResponse);
      this.$.myform.addEventListener('iron-form-error',this.formError);
}

Form Response Function:

formResponse: function (e){
                    console.log("Server Response: ",e.detail);
}

Form Error Function:

formError: function (e){
                    console.log("Form Error: ",e.detail);
}
like image 22
Talon Avatar answered Nov 16 '22 18:11

Talon