On multiple field errors, field focus is random.

On multiple field errors, field focus is random.

mslattery@misoenergy.orgmslattery@misoenergy.org Posts: 2Questions: 0Answers: 0
edited April 2017 in Editor

When multiple there are multiple field errors in the editor form, the focused field is random. We have a form with 5 fields, all required, and if I leave them all blank (which causes a field error), the focused field is randomly chosen between the first 3. I am even clicking the submit button at the exact same location.

Is there a way to make it always choose the first field that has an error?

Replies

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    On this example if you click the "New" button and then submit an empty form, it will always focus on the first field in error. The JSON handling code has a specific case for the 0 loop to make focus only call on that first field.

    It sounds like the response from the server might not always be in the same order. If that's the case, Editor will always pick the first in the current response. Might that be the case?

    Allan

  • mslattery@misoenergy.orgmslattery@misoenergy.org Posts: 2Questions: 0Answers: 0

    Right. The fieldsErrors returned is coming back in random order from our server. The first element in the array is what dictates the focus (i.e. i=0). It would be better for us if the order was based on the order of the fields array in the editor options.

    The server side code is unaware of the field ordering; it returns errors using logic independent of any editor configuration.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    At the moment I think you'd need to use the postSubmit event to reorder the items in the fieldErrors array into the same order as the form. A little sort() function should be able to do that.

    There isn't a built in way in Editor to have it handle that case at the moment I'm afraid - it is expecting the errors to be returned from the server in sequential order.

    Are you using async validators on the server - is that why they are coming back in a different order each time?

    Allan

This discussion has been closed.