drupal CCK:如何添加一个文本字段,其值取决于同一页面上的其他CCK字段?

发布于 2024-10-18 22:29:02 字数 331 浏览 5 评论 0原文

我面临这种情况,我有几个 CCK 字段,并且我希望自动配置其中一个字段,具体取决于一个/某些其他字段。

例如:假设我有以下字段:
字段1:[选择列表]
字段2:[日期选择器]
字段 3:[根据字段 2 的选择自动生成值]

因此,我的意图是,根据用户在 Field2 中选择日期的方式,我将自动生成并在 Field3 中显示一些值。

我猜 Field3 并不需要是 CCK 字段,因为它实际上根本不收集用户的任何信息。我真正想要的是这种“实时反馈”,用户可以看到在 CCK 字段中输入内容时会发生什么。

有什么想法吗?谢谢。

I'm facing this situation, where I have several CCK fields, and I want one of these fields to be auto configured depends on one/some of the other fields.

For example: suppose I have the following fields:
Field1: [selection list]
Field2: [Date Picker]
Filed3: [Auto generated value depending on the selection of Field 2]

So my intent here is that depending on how the user picks the dates in Field2, I'll automatically generate and show some value in Field3.

I guess Field3 doesn't really need to be a CCK field, as it's actually not collecting any information from the user at all. What I really want is this "real-time feedback" where users can see what happens if they input something in the CCK fields.

Any idea?Thanks.

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

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

发布评论

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

评论(1

っ左 2024-10-25 22:29:02

据我所知,除了 计算字段 之外,没有办法将业务逻辑分配给 CCK 字段德鲁帕尔。

如果您希望这样的业务逻辑来控制您的字段,那么我建议以下两个选项之一:

  1. 创建您自己的字段。这听起来很难,但实际上却很困难。最困难的部分是由于缺乏文档造成的:它需要阅读示例代码并反复试验。可以在 poplar 找到一个不错的教程。
  2. 使用自己的字段创建您自己的内容类型。到目前为止,这是最简单的。但它缺乏 CCK 的灵活性:您对此内容类型的字段进行硬编码,因此无法在其他内容类型上重复使用它们。如果不编写自己的视图集成和搜索索引以及其他扩展通常需要额外的工作,视图就不会集成到您的模块中。

也就是说,就我个人而言,最常选择最后一个;无论如何,当我为网站开发自定义内容时,我几乎不需要配置 GUI 以及所有选项和灵活性,那么为什么要费心开发它呢?
一个很好的例子是 CCK 字段可以是单个多个:您的架构及其代码需要覆盖这两个字段,否则东西就会损坏。即使您确信某个领域永远不需要多样性,您仍然会花费数小时来开发它。

As far as I know, other then the computed field there is no way to assign business logic to CCK fields in Drupal.

If you want such business logic to control your fields, then I suggest either one of two options:

  1. Create your own field. This sounds harder then it is; the hardest part is caused by lack of documentation: it requires reading example code and trial and error. A nice tutorial can be found at poplar.
  2. Create your own content-type with its own fields. This is, by far, the simplest. But it lacks the flexibility of CCK: you hardcode the fields on this content-type, so cannot re-use them on others. Views won't integrate in your module without writing your own views integration and search-indexing and other extensions often require additional work.

That said, I, personally, most often choose the last; I hardly ever need the configuration-guis and all the options and flexibility, when I am developing custom stuff for sites anyway, so why bother developing it?
A good example is the fact CCK fields can be singular and multiple: your architecture and its code will need to cover both, else stuff will break. Even if you know for sure you will never need multiplicity in a field, you'll still be spending hours developing it.

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