2011-12-19 101 views
1
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" 
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" 
xmlns:xforms="http://www.w3.org/2002/xforms"> 

<xhtml:head> 
    <xhtml:title>Orbeon XForms Sample Form</xhtml:title> 

    <xforms:model> 
    <xforms:instance id="myModel" xmlns=""> 
    <form> 
      <type> 

       <radio></radio> 
      </type> 
      <type> 

       <radio></radio> 
      </type> 
      <type> 

       <radio></radio> 
      </type> 
    </form> 
    </xforms:instance> 



    <xforms:bind id="radio" nodeset="instance('myModel')/type/radio"/> 


    </xforms:model> 
</xhtml:head> 

<xhtml:body> 

    <table> 
     <tr> 

     </tr> 
     <tr><td> 
      <table> 

      <xforms:repeat nodeset="instance('myModel')/type"> 

       <tr> 
        <td> 
         <xforms:output ref="position()"/> 
        </td> 
        <td/> 
        <td> 
         <xforms:select1 ref="radio" incremental="true" appearance="minimal"> 
          <xforms:item> 
           <xforms:label>Please Select</xforms:label> 
           <xforms:value></xforms:value> 
          </xforms:item><xforms:item> 
           <xforms:label>Yes</xforms:label> 
           <xforms:value>Yes</xforms:value> 
          </xforms:item> 
          <xforms:item> 
           <xforms:label>No</xforms:label> 
           <xforms:value>No</xforms:value> 
          </xforms:item> 
          <xforms:alert>Required</xforms:alert> 
         </xforms:select1> 
        </td> 
       </tr> 
      </xforms:repeat> 
      </table> 
     </td> 
     </tr> 

    </table> 

</xhtml:body> 

</xhtml:html> 

在上面的表格中,我想根據在前一個字段中選擇的值啓用字段。例如,如果我在第一個下拉列表中選擇是的,那麼應該啓用第二個下拉菜單。如果我在第二個下拉列表中選擇是的,那麼應該啓用第三個下拉菜單等等。我怎樣才能實現這個?我可以在xforms-value-changed事件中做些什麼嗎?或者我可以在xforms:bind中實現這個嗎?如何啓用或禁用另一個字段的值更改字段?

回答

2

正如你懷疑的那樣,你可以用xforms:bind來做到這一點。下面將做你的榜樣工作:

<xforms:bind id="radio" nodeset="instance('myModel')/type/radio" 
    relevant="empty(../preceding-sibling::type) 
       or ../preceding-sibling::type[1]/radio = 'Yes'"/> 

這裏最微妙的部分是利用preceding axis的獲得,只是目前的一個之前來了type元素。

+0

是的,它的工作方式正是我想要的..非常感謝你.. :) – Akshay 2011-12-21 11:30:59

+0

非常好,謝謝你的確認。 – avernet 2011-12-22 02:26:22

相關問題