Skip to content

Commit

Permalink
Remove tags, images, and files methods inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Feb 22, 2025
1 parent e5f96a0 commit fb154eb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion formwork/fields/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
$value = array_filter($value, static fn($item): bool => Constraint::matchesRegex($item, $field->get('pattern')));
}

if ($field->has('limit') && count($value) > $field->get('limit')) {
if ($field->limit() !== null && count($value) > $field->limit()) {
throw new ValidationException(sprintf('Field "%s" of type "%s" has a limit of %d items', $field->name(), $field->type(), $field->get('limit')));
}

Expand All @@ -75,5 +75,9 @@
'limit' => function (Field $field): ?int {
return $field->get('limit', null);
},

'isOrderable' => function ($field): bool {
return $field->is('orderable', true);
},
];
};
6 changes: 5 additions & 1 deletion formwork/fields/images.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
$value = array_filter($value, static fn($item): bool => Constraint::matchesRegex($item, $field->get('pattern')));
}

if ($field->has('limit') && count($value) > $field->get('limit')) {
if ($field->limit() !== null && count($value) > $field->limit()) {
throw new ValidationException(sprintf('Field "%s" of type "%s" has a limit of %d items', $field->name(), $field->type(), $field->get('limit')));
}

Expand All @@ -71,5 +71,9 @@
'limit' => function (Field $field): ?int {
return $field->get('limit', null);
},

'isOrderable' => function ($field): bool {
return $field->is('orderable', true);
},
];
};
10 changes: 9 additions & 1 deletion formwork/fields/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$value = array_filter($value, static fn($item): bool => Constraint::matchesRegex($item, $field->get('pattern')));
}

if ($field->has('limit') && count($value) > $field->get('limit')) {
if ($field->limit() !== null && count($value) > $field->limit()) {
throw new ValidationException(sprintf('Field "%s" of type "%s" has a limit of %d items', $field->name(), $field->type(), $field->get('limit')));
}

Expand All @@ -47,8 +47,16 @@
return $options !== null ? Arr::from($options) : null;
},

'accept' => function ($field): string {
return $field->get('accept', 'options');
},

'limit' => function ($field): ?int {
return $field->get('limit', null);
},

'isOrderable' => function ($field): bool {
return $field->is('orderable', true);
},
];
};
2 changes: 1 addition & 1 deletion panel/views/fields/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
'data-limit' => $field->limit(),
'data-options' => Formwork\Parsers\Json::encode($field->options()),
'data-accept' => 'options',
'data-orderable' => $field->is('orderable', true),
'data-orderable' => $field->isOrderable(),
]) ?>>
</div>
2 changes: 1 addition & 1 deletion panel/views/fields/images.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
'data-limit' => $field->limit(),
'data-options' => Formwork\Parsers\Json::encode($field->options()),
'data-accept' => 'options',
'data-orderable' => $field->is('orderable', true),
'data-orderable' => $field->isOrderable(),
]) ?>>
</div>
8 changes: 4 additions & 4 deletions panel/views/fields/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
'required' => $field->isRequired(),
'disabled' => $field->isDisabled(),
'hidden' => $field->isHidden(),
'data-limit' => $field->get('limit'),
'data-options' => $field->has('options') ? Formwork\Parsers\Json::encode($field->options()) : null,
'data-accept' => $field->get('accept', 'options'),
'data-orderable' => $field->is('orderable', true),
'data-limit' => $field->limit(),
'data-options' => $field->options() ? Formwork\Parsers\Json::encode($field->options()) : null,
'data-accept' => $field->accept(),
'data-orderable' => $field->isOrderable(),
]) ?>>
</div>

0 comments on commit fb154eb

Please sign in to comment.