XBL control's attributes

一个人想着一个人 提交于 2019-12-13 00:42:52

问题


I have my custom XBL control, let's say :

<fr:my-control id="my-control-id" attr1 = "value1 value2 value3" attr2 = "aaa" ../>

In my XBL I have defined a handler and attr1 as xf:select

<xbl:handlers>
    <xbl:handler event="my-custom-event" phase="target">
            <xf:send submission="my-submission"/>   
 </xbl:handler>
...
<xf:select ref="@subOn">

And in dialog.control.details I have added :

<xf:select appearance="full" ref="if ($xforms-control/self::xf:select) then $bound-node else ()">
    <xf:label>Send submission:</xf:label>
        <xf:item>
            <xf:label>On load</xf:label>
            <xf:value>load</xf:value>
        </xf:item>
        <xf:item>
            <xf:label>On save</xf:label>
            <xf:value>save</xf:value>
        </xf:item>                              
</xf:select>

So I can select load and save by clicking on checkboxes in control's settings. Now, I would like to dispatch some event ONLY IF attr1 contains specific word, f.e.

<fr:my-control id="my-control-id" attr1 = "save" attr2="...">

if(contains(normalize-space($attr1), 'save') then
<xf:dispatch ev:event="my-custom-event" observer="fr-form-model" name="my-custom-event"
  targetid="my-control-id"/>

</fr:my-control>

How would I do that ? Thanks in advance.

UPDATE

I would like to make myself perfectly clear, so :

1 Inside my form generating in Form Builder there I have :

<fr:my-control id="my-control-id" attr1 = "save">
<xf:dispatch ev:event="my-custom-event" observer="fr-form-model" name="my-custom-event"
  targetid="my-control-id"/>
</fr:my-custom-control>

I placed this <xf:dispatcher> to catch event when user clicks on Save button in Form Runner. There is also a problem with targetid which I have to set always by hand to be the same as fr:my-custom-control but there's another issue which has its own post.

2 Inside XBL file there i have handlers defined

<xbl:handlers> <xbl:handler event="my-custom-event" phase="target"> <xf:send submission="my-submission"/> </xbl:handler> </xbl:handlers>

<xf:input ref="@attr1"/>

This handler catches my-custom-event and sends my-submission afterwards. It is done OUTSIDE xbl:template.

3 I want to send such submission only if attr1 = "save".

I tried to do this :

<xf:template>
<xf:var name="attr1" xbl:attr="xbl:text=attr1" >
    <xf:action ev:event="xforms-enabled xforms-value-changed">
        <xf:setvalue ref="instance('attr1')" value="$attr1"/>
    </xf:action>
</xf:var>
<xf:model>
    <xf:instance id="attr1"><value/></xf:instance>
        <xf:group ref=".[contains(normalize-space($subOn), 'save')]">
            <xf:submission id="my-submission" ..
              ..
            </xf:submission>
        </xf:group>
</xf:model>

That way submission is never sent. Also I tried only adding condition to submission, like this :

<xf:submission id="my-submission" 
        if="contains(normalize-space($attr1), 'save')"
        ...>
</xf:submission>

Ironically, this way submission is always sent, no matter what attr1 actually is.

It's not working and I have no idea why. Code seems right, but obviously there must be something wrong.


回答1:


From XForms, you can't access the value of another element in the DOM, so in this case, you can't access from "outside" fr:my-control the value of its attr1 attribute. On the other side, the implementation of the XBL component can of course access the value of its attributes. The simplest way to do that is to declare inside the XBL control a variable, e.g.:

<xf:var name="attr1-attribute" xbl:attr="xbl:text=attr1"/>

Then, you can use, inside the control $attr1 to refer to the value of the attr1 attribute. Would it work for you to move that logic inside the XBL component, i.e. do the xf:send only if $attr1 = 'save'?



来源:https://stackoverflow.com/questions/28153693/xbl-controls-attributes

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