I am submitting a form using iron-form. However, when the server responds, I want to see what the response is so that I can:
I realise I can easily listen to iron-form-error
to see if there were any problems. The error comes back as Json, where I have key/value where the key is the field name, and the value is the error message.
In case the response was indeed an error, do I have to go through the response manually? Or is there a shorthand version to display the error messages automagically?
Thank you!
Are you doing any pre-validation with validators attached to the inputs? These will provide error messages that you have put in the error-message attribute of the input. When the response comes back you can just set the paper-input to invalid.
I have a password change dialog that is like this. It uses a validator to check that password 1 and password 2 are the same, but the server also checks this too. In this case it sends a valid json response (ie not an error) with the response json object containing an field that tells me that particular field is wrong (as a boolean). Here is a fragment of my response after earlier I have done var response = e.detail.response;
if (response.status) {
this.$.profiledialog.close();
this._setNopass(false); //just get this back to its default state
} else {
if (!response.passwd1) {
if (response.passwd2) {
this.$.pw1.invalid = true;
this.$.pw1.focus();
} else {
throw new Error('Profile Update Server Failure');
}
}
if (!response.passwd2) {
this.$.pw2.invalid = true;
this.$.pw2.focus();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.