Skip to content

Commit

Permalink
[5.x] Prevent configuring multiple conditions for the same field (#10110
Browse files Browse the repository at this point in the history
)

Co-authored-by: Jason Varga <[email protected]>
  • Loading branch information
duncanmcclean and jasonvarga authored May 17, 2024
1 parent 61f487c commit ff8bbc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions resources/js/components/field-conditions/Builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
:index="index"
:config="config"
:condition="condition"
:conditions="conditions"
:key="condition._id"
:suggestable-fields="suggestableFields"
@updated="updated(index, $event)"
Expand Down
12 changes: 11 additions & 1 deletion resources/js/components/field-conditions/Condition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export default {
type: Object,
required: true
},
conditions: {
type: Array,
required: true
},
index: {
type: Number,
required: true
Expand Down Expand Up @@ -116,8 +120,14 @@ export default {
},
fieldOptions() {
const conditions = this.conditions.map(condition => condition.field);
return _(this.suggestableFields)
.reject(field => field.handle === this.config.handle || this.condition.field === field.handle)
.reject(field => {
return field.handle === this.config.handle // Exclude the field you're adding a condition to.
|| this.condition.field === field.handle // Exclude the field being used in the current condition.
|| conditions.includes(field.handle); // Exclude fields already used in other conditions.
})
.map(field => {
let display = field.config.display;
Expand Down

0 comments on commit ff8bbc9

Please sign in to comment.