문제

How to access the state of PrimeFaces p:inplace component in Javascript?

I need to check if the component is in state inline or not, in order to call toggle()function when needed... AFAIK toggle() can only change the state and not set the state to desired value?

도움이 되었습니까?

해결책

Suppose you got something like thisL

<p:inplace id="basic" widgetVar="myWidget">  
    <p:inputText value="Edit Me" />  
</p:inplace>  

You can check if the inplace was opened with the help of the widgetVar and jQuery , like this

jQuery(myWidget.content).is(":visible")

Or you can check it with the :visible selector and the id of the inplace :

append _display to your inplace element id to check if the editor wasn't open yet

append _content to your inplace element id to check if the editor was already open

jQuery("#basic_display").is(":visible")

jQuery("#basic_content").is(":visible")

you can check it in browser console in the showcase Primefaces Inplace

다른 팁

I have achieved it with checking the CSS display value of ui-inplace-display and ui-inplace-content elements:

            $('.ui-inplace-display').filter(function(){
                return $(this).css('display') == 'inline';
            }).toggle();
            $('.ui-inplace-content').filter(function(){
                return $(this).css('display') == 'none';
            }).toggle();

However, for me it's more a hack that a solution, so I'd expect something more elegant, such as a state in dedicated attribute of JavaScript object, or at least dedicated CSS class for that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top