Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying of rules manually #141

Merged
merged 6 commits into from
Oct 17, 2023
Merged

Conversation

morrislaptop
Copy link
Contributor

When manually specifying keys because of migrating existing db / json fields, the ConditionalLogic class can't / won't use the manually specified key.

This change allows the rules to be specified manually and bypass the ConditionalLogic class.

Example:

TrueFalse::make('Display Webinar Chapters?')
  ->key('field_64c842b5238bc'),

Text::make('Webinar Chapters')
  ->key('field_64c8422d238b7')
  ->conditionalLogic([
      ['field' => 'field_64c842b5238bc', 'operator' => '==', 'value' => 1]
  ])

When manually specifying keys because of migrating existing db / json fields, the ConditionalLogic class can't / won't use the manually specified key.

This change allows the rules to be specified manually and bypass the ConditionalLogic class.

Example:

```php
TrueFalse::make('Display Webinar Chapters?')
                ->key('field_64c842b5238bc'),

            Text::make('Webinar Chapters')
                ->key('field_64c8422d238b7')
                ->conditionalLogic([
                    ['field' => 'field_64c842b5238bc', 'operator' => '==', 'value' => 1]
                ])
```
@vinkla
Copy link
Owner

vinkla commented Oct 17, 2023

Thank you for the pull request! I appreciate the use case. I've started migrating a project from JSON to PHP too. Please include tests for this change and let's add a code comment to explain the reason for the implementation. Additionally, we should convert this into a regular function.

@morrislaptop
Copy link
Contributor Author

@vinkla added test and comment. Not sure what / why we need to convert into a regular function?

@vinkla
Copy link
Owner

vinkla commented Oct 17, 2023

Not sure what / why we need to convert into a regular function?

Just to make the code more readable. I can make that adjustment.

@vinkla
Copy link
Owner

vinkla commented Oct 17, 2023

I have come up with another solution.

ConditionalLogic::where(
    name: 'select',
    operator: '==',
    value: 'red',
    key: 'field_123abc'
)

Please use the branch alias "13.9" to test this feature. We will release it after a period of testing.

Thanks for the pull request Craig 🙌

@vinkla vinkla merged commit dabe597 into vinkla:master Oct 17, 2023
3 checks passed
@morrislaptop morrislaptop deleted the patch-1 branch October 17, 2023 11:41
@morrislaptop
Copy link
Contributor Author

Great!

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