Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/js/components/field-conditions/Validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export default class {
values: this.values,
root: this.rootValues,
fieldPath: this.currentFieldPath,
prefix: this.field.prefix,
...this.extraPayload,
});

Expand Down
14 changes: 14 additions & 0 deletions resources/js/tests/FieldConditionsValidator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,20 @@ test('it can call a custom function', () => {
expect(Fields.showField({ unless: 'custom reallyLovesAnimals' })).toBe(true);
});

test('it can call a custom function that uses `prefix` param to evaluate prefixed fields', () => {
setValues({
first_favorite_animals: ['cats', 'dogs', 'giraffes', 'lions'],
second_favorite_animals: ['cats', 'dogs'],
});

Statamic.$conditions.add('reallyLovesAnimals', function ({ prefix, values }) {
return values[`${prefix}favorite_animals`].length > 3;
});

expect(Fields.showField({ prefix: 'first_', if: 'custom reallyLovesAnimals' })).toBe(true);
expect(Fields.showField({ prefix: 'second_', if: 'custom reallyLovesAnimals' })).toBe(false);
});

test('it can call a custom function that uses `fieldPath` param to evaluate nested fields', () => {
setValues({
nested: [{ favorite_animals: ['cats', 'dogs'] }, { favorite_animals: ['cats', 'dogs', 'giraffes', 'lions'] }],
Expand Down
Loading