Skip to content

Conversation

@wblommaert
Copy link

Recently we were trying to use some of our Preparse field values as conditionals to show and hide other fields in our field layouts but realised this isn't possible at the moment. This PR enables the Preparse field values to be used as part of the conditional field layouts in Craft CMS by adding the getElementConditionRuleType function to the PreparseFieldType class.

To account for the different underlying column types that Preparse offers, the function will automatically check for the used column type and return the corresponding, existing field condition rule that Craft CMS already provides. In case this ever gets expanded on, the default TextFieldConditionRule will be returned. At the moment it will provide support for DateFieldConditionRule, NumberFieldConditionRule and TextFieldConditionRule.

An example use case (ours in this case) is:

  • We have authors that administrate one page via the control panel
  • Depending on whether the author has a paid plan, certain fields will be hidden or shown
  • We preparse a number value on the page entry by using the user's payment details
  • We use the preparsed 1 or 0 value to show or hide specific fields that can only be accessed when you're a paid user

I'd be more than happy to hear and apply any feedback or questions you might have!

This enables the preparse field to be used as part of the conditional field layouts in Craft CMS.
@ishetnogferre
Copy link

Hi @jalendport, we'd also benefit from having this available in an upcoming project. Any plans to implement this?

I'm gonna start with a fork with the above changes, so can also provide feedback (if it works well in Craft 5).

@ishetnogferre
Copy link

Can confirm in first tests, this works 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants