Apostrophe 2是否支持条件字段?相关功能文档咨询
Great question—let's tackle this head-on!
First, the core answer: Apostrophe 2 does not include built-in support for conditional fields (the ability to show/hide fields based on the value of another field) out of the box.
You’re correct to note that discussions about this feature exist in the apostrophecms-legacy repository, but these are mostly historical community conversations or unofficial workarounds. There is no official, maintained documentation for conditional fields in Apostrophe 2 from the core team.
If you need this functionality for your project, you’ll have to implement it using custom frontend JavaScript. Here’s a simplified example of how you might approach this:
// Add this to your module's editor.js file apostrophe('ready', function() { // Replace with your actual field selectors const triggerField = document.querySelector('[name="your-trigger-field-name"]'); const targetFieldContainer = document.querySelector('[data-field="your-target-field-name"]'); if (triggerField && targetFieldContainer) { // Define the toggle logic const toggleFieldVisibility = () => { // Adjust the condition to match your use case targetFieldContainer.style.display = triggerField.value === 'specific-value' ? 'block' : 'none'; }; // Set initial visibility when the editor loads toggleFieldVisibility(); // Update visibility when the trigger field changes triggerField.addEventListener('change', toggleFieldVisibility); } });
Just a heads-up: these custom workarounds aren’t officially supported, so you’ll need to maintain them as Apostrophe 2 receives updates.
内容的提问来源于stack exchange,提问作者Carsten

