XBL 控件的属性 [英] XBL control's attributes

查看:49
本文介绍了XBL 控件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的自定义 XBL 控件,比方说:

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

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

在我的 XBL 中,我将处理程序和 attr1 定义为 xf:select

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">

dialog.control.details 中,我添加了:

<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>

因此我可以通过单击控件设置中的复选框来选择 loadsave.现在,我想仅在 attr1 包含特定单词 f.e.

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.

更新

我想让自己完全清楚,所以:

I would like to make myself perfectly clear, so :

1 在我在 Form Builder 中生成的表单中,我有:

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>

我放置了这个 <xf:dispatcher> 以在用户单击 Form Runner 中的 Save 按钮时捕获事件.targetid 也存在问题,我必须始终手动将其设置为与 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 在 XBL 文件中,我定义了处理程序

2 Inside XBL file there i have handlers defined

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

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

此处理程序捕获 my-custom-event 并随后发送 my-submission.它是在 xbl:template 之外完成的.

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

3 我只想在 attr1 = "save" 时发送这样的提交.

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

我尝试这样做:

<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>

具有讽刺意味的是,无论attr1实际上是什么,总是以这种方式发送提交.

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.

推荐答案

从 XForms 中,您无法访问 DOM 中另一个元素的值,因此在这种情况下,您无法从外部"访问 fr:my-controlattr1 属性的值.另一方面,XBL 组件的实现当然可以访问其属性的值.最简单的方法是在 XBL 控件内部声明一个变量,例如:

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"/>

然后,您可以在控件中使用$attr1 来引用attr1 属性的值.在 XBL 组件中移动该逻辑是否对您有用,即仅当 $attr1 = 'save' 时才执行 xf:send?

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'?

这篇关于XBL 控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆