How to associate API error with a field?

Options

I am using the example API code to track/catch errors coming back.

Using the following (snippet):

// Kind of a hack - look at the text of the error to determine

// where to display the error message.

for (var

i = 0; i < fieldErrors.length; i++) {

..

if (fieldErrors.toLowerCase().indexOf('title') > -1) {

_fieldErrorMessage = document.getElementById(

'TitleError');

_fieldErrorMessage.innerHTML = fieldErrors;

_fieldErrorMessage.style.display =

'';

}

..

Two questions:

1) What if I have a field named "joint_donor.name.title", this code will get confused? I will need a more discriminating comparison to find the correct field association, or do you have a more robust example/solution?

2) What if the error is a generic one, for example: "Response is too long"

To get this error, I purposely typed more chars in a few fields than the ghost form fields can hold - it cannot find which field the error occured on.

Of course, I can limit the input field size so that doesn't happen, but do you have a solution where every error returned is associated with the field name/id?

There are situations where I will not forsee all the possible errors and may not code for them to catch on input, then when I get an error that doesn't associate I have to spend a lot of time figuring out where it belongs.

Tagged:

Categories