XForms 输入中的默认值

发布于 2024-08-11 23:23:40 字数 508 浏览 6 评论 0原文

我有一个 XForm,其中某些字段可能经常留空(可选街道地址)。是否有技术可以为该字段设置默认值,最好是一个空格(我遇到了奇怪的 CSS 格式问题)。 value="" 的 html 表单方式不起作用,在 XML 模式中设置默认值也不起作用。

示例:

<xforms:input ref="clientaddress/streetaddress2" model="model_inventory" >
        <xforms:label>Street Address (Line 2)</xforms:label>

将此字段留空会导致生成的 xml 文档中的 />

我想要

<streetaddress> </streetaddress>

I have an XForm that has certain fields that may often be left blank (optional street address). Is there is technique to set a default value for that field, preferably a space (I am running into weird formatting issues with CSS). The html form way of value="" doesn't work, neither does setting a default value in the XML schema.

EXAMPLE:

<xforms:input ref="clientaddress/streetaddress2" model="model_inventory" >
        <xforms:label>Street Address (Line 2)</xforms:label>

Leaving this field blank results in <streetaddress2/> in the resulting xml document

I want

<streetaddress> </streetaddress>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戈亓 2024-08-18 23:23:40

您是说您想将实例中所有空白字段的值设置为有空格吗?假设您有一个静态实例,您可以将以下内容添加到模型中:

<xforms:setvalue ev:event="xforms-model-construct-done" 
    xxforms:iterate="//*[empty(*) and string() = '']" ref="."> </xforms:setvalue>

请注意,这使用 Orbeon Forms 的 xxforms:iterate 扩展 (记录在此处)。如果您正在使用另一个 XForms 实现,您可能需要检查该实现的文档以查看它们是否提供类似的扩展。

(话虽这么说,我很好奇为什么你需要在“空”字段中留有一个空格。这可能是其他地方出现问题的迹象吗?)

Are you saying that you would like to set the value of all the fields in your instance that are blank to having a space? Assuming you have a static instance, you can add the following to your model:

<xforms:setvalue ev:event="xforms-model-construct-done" 
    xxforms:iterate="//*[empty(*) and string() = '']" ref="."> </xforms:setvalue>

Note that this uses the xxforms:iterate extension of Orbeon Forms (documented here). If you are using another XForms implementation, you might want to check the documentation of that implementation to see if they provide a similar extension.

(This being said, I am curious as to why you need to have a space in the "empty" fields. Could that be a sign of a problem somewhere else?)

青瓷清茶倾城歌 2024-08-18 23:23:40

在 XForms 中设置默认值的最简单方法是实例:

<xforms:instance>
  <data>
    <clientaddress>
      <streetaddress> </streetaddress>
    </clientaddress>
  </data>
</xforms:instance>

您说过,您尝试在模式中设置默认值,但我不确定它是否按您的预期工作。模式可用于验证,但我不知道是否有任何 XForms 引擎使用模式的默认值。

The easiest way to set default value in XForms is the instance:

<xforms:instance>
  <data>
    <clientaddress>
      <streetaddress> </streetaddress>
    </clientaddress>
  </data>
</xforms:instance>

You said, that you tried to set default value in schema, but I'm not sure that it works as you expected. Schema can be used for validation, but I don't know if any XForms engine uses schema's default values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文