default return key action in editor
default return key action in editor
is it possible to define default return action in editor as goto next input in the form (like tab key) ?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
using formOptions onReturn ?
I would use formOptions to turn off the submit when hitting the return key:
https://editor.datatables.net/reference/option/formOptions.main
In addition you would need to make sure the return key behaves like the tab key. Here is something on how to do this. The Editor api won't help you there I guess.
https://stackoverflow.com/questions/1009808/enter-key-press-behaves-like-a-tab-in-javascript
If you want to change the form options globally for all Editor instances you would need to do something like this:
I found this here: https://editor.datatables.net/reference/type/form-options
Looks like things have changed a little you should no longer return "false" but rather a string: "none".
In addition you can pass a function. You might be able to effect the change of the return key to become another tab key in this function as well. This would make things easier.
thanks @rf1234
The way you tell me do the job to focus next field in the form. I extend it to loop to first field when enter key pressed on last field.
I found a focus option at form construction options on same page you tell me. As we can know the list of fields in, if we can know the current focused one (not sure) is there a way in callback func to set focus on next form field ?
Another point (seem starnge)
I see if using tab key in form, the focus goes away the form after last form control with no event like onBlur fired... and we can navigate to another url with no event to catch..
Yes, use
field().focus()
.There isn't a method to get the currently focused field though. You could however use
document.activeElement
combined withfield().node()
to find out which field you are in:It won't work quite right if you are using checkboxes or radios, but it could be extended for that if you require it.
Allan
Thanks @allan
Yes, as shown above I need to go to next focus for each fields in editor on return key.
As I said, if using tab key, the focus can go away the form (and the application to) going in browser buttons for example.
In this case, the preBlur or preClose does not fire... Is it normal ?
running good for focus with loop in form fields only