Closed andrey-bahrachev closed 9 years ago
Hi andrey-bahrachev, thank you for your post. If you don't want that an element in the modal is focused, try this:
modal.on('plainmodalopen', function() { $(document.activeElement).blur(); });
Note that this is safe than document.activeElement.blur()
.
Your request might be difficult because plainModal must unfocus a current active element when the modal opens, to avoid focusing the outside elements of the modal.
Before, I tried blur()
, but it doesn't work in some browsers and some situations. Then plainModal focuses an element in the modal instead of using blur()
.
That is, you should test above code.
Thanks for such a quick response. Yeah, it's not a problem to remove the focus from the element, it was the first thing I did. I'll explain a bit the issue I was facing. When I load the form in the modal which contains a text input field followed by a textarea field with Redactor editor attached to it, and then try to paste some text into the Redactor it gets pasted into the text field above it instead (that text field is exactly the one that receives the focus upon modal open), which is really unexpected and weird. Moreover, there are no errors whatsoever in the console. Removing focus the way you proposed doesn't help in this case. As an experiment I tried to comment out the piece of code in you plugin that is responsible for setting the focus and then I was able to paste the text normally. So I decided to open this issue. Anyway, I've circumvented that problem by setting Redactor's 'focusEnd' setting to true which forces the focus on it upon the modal open and stops that odd behavior. Maybe it'll help someone else :) Thanks!
Thank you for your report.:smiley:
I think that changing the active element by focusEnd
is no problem, because plainModal focuses a first element in the modal to unfocus a current active element absolutely.
Hey anseki, Thanks for the great plugin! It would be nice though to have the focusing upon modal open optional.