networkteam/fusionform-displaycondition
Composer 安装命令:
composer require networkteam/fusionform-displaycondition
包简介
Control the visibility (JavaScript) of Neos Fusion Form elements while filling out the form.
README 文档
README
Control the visibility of Neos Fusion Form elements while filling out the form.
A display condition ensures that an element is only displayed if the configured condition is fulfilled. A subset of JavaScript (networkteam/eel) can be used for this purpose. Form values can be referenced using the element identifier.
Installation
Required package via composer.
composer require networkteam/fusionform-displaycondition
Prerequisites
For using display conditions within a form a few prerequisites must be met:
- The CSS class
dynamic-formmust be applied to the<form>tag - The
<form>tag must have anidattribute with the forms namespace as value - Add tags to
Neos.Neos:Pagefor loading stylesheet and JavaScript
This package does that already by extending Neos.Fusion.Form:Form and Neos.Neos:Page.
Usage
Add id to form control you want to interact with
To dynamically show or hide elements (based on entered form values) within a form, you must set an id for the controls
you want to interact with. The id is used as variable name inside display condition expression.
Add data attribute holding display condition expression
Any component inside your form which visibility you want to control via condition must have a data-display-condition
attribute. The value is a Javascript EEL expression.
Use the provided helper (Networkteam.FusionForm.DisplayCondition:Helper.DisplayConditionAugmenter) to add the required
data attribute to your components.
Example:
prototype(Vendor.Site:Content.SingleStepFormExample) < prototype(Neos.Fusion.Form:Runtime.RuntimeForm) {
// set context variable to enable usage of display conditions. When set to `false` no display condition related
// attribute will be renderd
@context.displayConditionEnabled = true
namespace = "single_step_form_example"
process {
content = afx`
<Neos.Fusion.Form:FieldContainer field.name="firstName" label="First Name">
<Neos.Fusion.Form:Input />
</Neos.Fusion.Form:FieldContainer>
<Neos.Fusion.Form:FieldContainer field.name="lastName" label="Last Name">
<Neos.Fusion.Form:Input />
</Neos.Fusion.Form:FieldContainer>
<!-- show picture field only, if firstName and lastName has been filled out -->
<Neos.Fusion.Form:FieldContainer field.name="picture" label="Picture" displayCondition="firstName && lastName">
<Neos.Fusion.Form:Upload />
</Neos.Fusion.Form:FieldContainer>
<Neos.Fusion.Form:FieldContainer field.name="birthDate" label="BirthDate">
<Neos.Fusion.Form:Date />
</Neos.Fusion.Form:FieldContainer>
<Neos.Fusion.Form:FieldContainer field.name="sports" field.multiple label="Sports">
<Neos.Fusion.Form:Select>
<Neos.Fusion.Form:Select.Option option.value="climbing" />
<Neos.Fusion.Form:Select.Option option.value="biking" />
<Neos.Fusion.Form:Select.Option option.value="hiking" />
<Neos.Fusion.Form:Select.Option option.value="swimming" />
<Neos.Fusion.Form:Select.Option option.value="running" />
</Neos.Fusion.Form:Select>
</Neos.Fusion.Form:FieldContainer>
`
schema {
firstName = ${Form.Schema.string().isRequired()}
lastName = ${Form.Schema.string().isRequired().validator('StringLength', {minimum: 6, maximum: 12})}
picture = ${Form.Schema.resource().isRequired().validator('Neos\Fusion\Form\Runtime\Validation\Validator\FileTypeValidator', {allowedExtensions:['txt', 'jpg']})}
birthDate = ${Form.Schema.date().isRequired()}
sports = ${Form.Schema.arrayOf( Form.Schema.string() ).validator('Count', {minimum: 1, maximum: 2})}
}
}
action {
message {
type = 'Neos.Fusion.Form.Runtime:Message'
options.message = afx`<h1>Thank you {data.firstName} {data.lastName}</h1>`
}
email {
type = 'Neos.Fusion.Form.Runtime:Email'
options {
senderAddress = ${q(node).property('mailFrom')}
recipientAddress = ${q(node).property('mailTo')}
subject = ${q(node).property('mailSubject')}
text = afx`Thank you {data.firstName} {data.lastName}`
html = afx`<h1>Thank you {data.firstName} {data.lastName}</h1>`
attachments {
upload = ${data.picture}
}
}
}
}
}
// Code is taken from https://github.com/neos/fusion-form/blob/master/Documentation/Examples/SingleStepForm.md
Compile Javascript
The Javascript is compiled with esbuild. Run the following commands on CLI:
yarn install
yarn build
networkteam/fusionform-displaycondition 适用场景与选型建议
networkteam/fusionform-displaycondition 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 3k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 06 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 networkteam/fusionform-displaycondition 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 networkteam/fusionform-displaycondition 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-06-02