This is a continuation of a question I asked previously: jQuery Validate, Select2, and Bootstrap 3 Popovers - How to Bind Popover To Select2's Parent Elements Instead of Hidden Select Element
While the issue with Select2 was resolved, the issue with CKEditor never did, and while at the time I resorted to an alternate solution, I would prefer to use the popovers since they do not alter document layout when triggered.
Here is a Fiddle of my current issue: http://jsfiddle.net/jemxtthb/13/
I know it has to do with the chaining of selectors in the if statement - I put in some console output to ensure that it is triggering the popover on the CKEditor element:
if (element.is(':hidden')) {
$(element).siblings().next().popover('show').parents('.form-group').addClass('has-error').removeClass('has-success');
console.log('hidden element');
} else {
$(element).popover("show").parents(".form-group").addClass('has-error').removeClass('has-success');
console.log('normal element');
}
You can see in the Elements tab in Chrome's Developer Tools that the popover is being triggered, but it ends up being in the upper left corner of the viewport. How can I attach it to the CKEditor DIV, or at least something around it like the form-group
DIV surrounding it?
Oddly enough, there's no problem with the Select2 replaced element positioning; I suspect that has to do with the fact they use aria-hidden
rather than the CKEditor's display: none visibility: hidden
method.
Any help/advice is appreciated, and hopefully will benefit others who might be struggling with a similar issue.
First, only use the
errorPlacement
andsuccess
functions for showing/hiding and NOT the error/valid class assignments.Second, put everything that has to do with CSS classes into the
highlight
andunhighlight
functions.Third, by commenting out the various lines above, you can see that the CSS classes have nothing to do with the placement of the popup. Your popup is appearing in the upper-left corner of the window because it's always being attached to the element being validated that's represented by
element
; and in the case of the CKEditor, the root element is hidden.Since you initialize
.popover()
on$(element)
, then that's all it's ever going to do. You must initialize and show it on the visible element. In my example below, I select the immediate parent of the hiddentextarea
, which is$(element).parent()
. Then I chained.popover('show')
to the initialization...Then I put this inside your conditional...
Put all of above together, then adjust selectors and DOM traversal as you wish...
DEMO: http://jsfiddle.net/c6n30n0L/1/