messages disappear when hitting ENTER inside form
messages disappear when hitting ENTER inside form
Hi all,
In some cases, I am disabling the form submission by intercepting preSubmit event and returning false. This ensures that even if the user hits ENTER (rather than clicking on the "create" button), the form will not submit.
However, any messages I post using .message("field", "text") disappear immediately when I hit ENTER, even though the preSubmit event returns FALSE and prevents submission... so I need to do some duplicate work to re-evaluate my form in the preSubmit event, which is kind of bad practice.
Is there any way to prevent submission without losing all the messages?
tnx
This question has an accepted answers - jump to answer
Answers
I think the covered some of this in the thread from yesterday, but are you able to show me the code you are using so I can see exactly what is going on please?
Thanks,
Allan
My validation is not using the validation framework of Editor (maybe it should?). The reason is that validation occurs while the user types - not when he hits "create". The on-the-fly validation even shows/hides additional fields as needed, depending on the existing input.
The code is simple:
`// in onOpen event:
editor.message("name", "the name of the person"
// in onPreSubmit event, just for the sake of testing:
return false;
`
Now, all I do is hit ENTER while adding a new item, the message disappears but the dialog isn't dismissed, so I need to re-apply it...
hope this helps.
sorry, markdown problems, preview doesn't work for some reason...
Ah I see - you are using on-the-fly validation. Presumably you are also doing validation at the server-side though? The default Editor setup doesn't do client-side validation since it has to be done at the server anyway, so rather than duplicating the logic it just uses the server's information. However, that is different for on-the-fly validation, since you don't want to be hitting the server for every key press.
If you have a look in the
Editor.prototype.submit
function you'll see that Editor is indeed clearing all error messages (message fields however shouldn't be cleared... are they, even with the fix from the other thread in?) as we assume that the server is going to tell us if the field is in error or not.Regards,
Allan
Ha! the message() fix indeed fixed the ENTER issue as well - two birds with one stone, pardon my non vegan proverb ;)