question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

As a developer, I can show and hide fields based on the values of other fields in an intuitive way

See original GitHub issue

Apostrophe 3.x doesn’t have showFields support so far. This 2.x feature needs to be ported, or reconsidered.

The backend logic for showFields, which ensures a required field is only really required if it is visible, is already present.

We depend rather heavily on this feature across many projects, as do others. I don’t think we can leave it out in 3.x, maybe not even for alpha.

However, this is our last chance for 3.x to decide if we change from showFields to something like if (or ifFieldEquals), which some have proposed because it is more common in other systems. It also is a bit familiar to Vue developers because it works a little like v-if.

The big difference is that if is set on the field that will be shown or hidden, and makes reference to another field’s value, as opposed to the other way around.

I have a bias against making any more changes in A3 because we’re due for a release and there will be an A4 one day.

However, if it turns out that if is less complicated to implement than showFields, it would be reasonable to do it. I think this is the case.

if could look like this:

ship: { 
  type: 'boolean'
},
shippingAddress: {
  type: 'string',
  if: {
    ship: true
  }
}

Like showFields, if would need to imply that a field is not required when it is not visible. Ditto for its subfields.

There are situations where a field could become visible in two or more ways. showFields supports this, so if potentially should too. We might not have to have parity on that right away, but if we do need it, we could support a mongo-style $or query.

As for implementation, it is tempting to restore the context prop to our input components, but that would give fields more information than they need to have and could have negative impacts on reactivity in Vue.

And in fact the responsibility for showing or hiding a field is not on the field, it is on AposSchemas. I say that because it is the same logic for every field, so AposSchemas can implement it in one place without making our mixin more complicated. Also, AposSchemas is the right place to use v-if to control whether the component is present.

Since the responsibility is on AposSchemas, which can see all the fields, we could implement either showFields or if. But, it seems to me that the implementation of if requires less code.

So discussion is needed to settle on an approach here. And I think we can make that decision on the merits of showFields versus if from the website developer’s standpoint, because both are reasonable to implement. Your input is welcome.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:39 (37 by maintainers)

github_iconTop GitHub Comments

3reactions
boutellcommented, Mar 2, 2021

In an engineering team meeting with Ben present, we agreed to:

  • Implement a small subset of the mongodb syntax for the initial 3.x stable release.
  • This will definitely include simple equality tests, with support for testing more than one property.
  • Follow the MongoDB syntax if we add additional functionality in 3.x.
  • Use Sift as our implementation, if we reach a point where the implementation effort of doing it ourselves justifies bringing in a library.

As a specification of the maximum feature set that could eventually be added, please see the sift documentation, with the exception of $where and any other sift features that involve inline functions, because those features do not transmit to the browser well.

We’re making this choice without any bias as to what might make sense in a future release.

3reactions
agilbertcommented, Feb 26, 2021

So far, Greg’s suggestion looks the most straightforward and understandable while also being flexible.

@boutell can you share examples of what you can / can’t do for logic here if we’re maintaining server and browser side compatibility?

For things you can’t do, can this be handled with clear documentation and error handling?

Read more comments on GitHub >

github_iconTop Results From Across the Web

show/hide fields based on another fields vaule - ServiceNow
I am trying to build a user enablement form that will dynamically update the software list based on the department field.
Read more >
Show / Hide fields based on other Field drop down
Solved: Hi Team, Is there a way to Show / Hide fields based on other Field drop down values on Customer Portal? Thanks,...
Read more >
How to hide fields on the New Entry Form in SharePoint List
In this video, I explain how you can easily hide and change the order of the fields on the New Entry form in...
Read more >
A Comprehensive Guide to REDCap
Each record is composed of a number of fields (pieces of data), which can be spread across multiple forms (instruments) per record. Record...
Read more >
Use Create Formula for Document- and Role-Based Access Control
In such scenarios, they can use Create Formula's role-based access control. ... The field author name can take other values as well, such...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found