JavaScript composite component nested forms

纵然是瞬间 提交于 2019-12-13 20:54:24

问题


I have a simple composite component, which is nested in some form etc. I would like to bind the click event for all radio buttons in the <h:selectOneRadio> of this composite component. I am trying to bind this event by name property of inputs which will be created after <h:selectOneRadio id>. Unfortunetly it is nested, so this code doesn't work, because the generated radio button ID is like:

"form:someid:someid:someid etc ect."

Composite component code:

<cc:implementation>
    <..some forms etc.>
        <h:selectOneRadio id="#{cc.attrs.id}" value="#{cc.attrs.value}">
            <cc:insertChildren/>
        </h:selectOneRadio>
    </..some forms etc.>

    <script type="text/javascript">
    /* <![CDATA[ */

        $('input[name=#{cc.attrs.id}]').click(function() {
                console.log("click");

        });

    /* ]]> */
    </script>
</cc:implementation>

Client code:

<mycomps:radio id="testID" ... >
    <f:selectItem itemLabel="test" itemValue="false"/>
    <f:selectItem itemLabel="test2" itemValue="true"/>
</mycomps:radio>

来源:https://stackoverflow.com/questions/21302781/javascript-composite-component-nested-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!