'{@$field->getPrefixedId()}',
[{if $field->getValue() !== null && !$field->getValue()|empty}{implode from=$field->getValue() item=item}'{@$item|encodeJS}'{/implode}{/if}],
{
- maxItems: {if $field->getMaximum() !== null}{@$field->getMaximum()}{else}-1{/if},
+ maxItems: {if $field->allowsMultiple()}{@$field->getMaximumMultiples()}{else}1{/if},
submitFieldName: '{@$field->getPrefixedId()}[]'
}
);
'{@$field->getPrefixedId()}',
[{if $field->getValue() !== null && !$field->getValue()|empty}{implode from=$field->getValue() item=item}'{@$item|encodeJS}'{/implode}{/if}],
{
- maxItems: {if $field->getMaximum() !== null}{@$field->getMaximum()}{else}-1{/if},
+ maxItems: {if $field->allowsMultiple()}{@$field->getMaximumMultiples()}{else}1{/if},
submitFieldName: '{@$field->getPrefixedId()}[]'
}
);
* @package WoltLabSuite\Core\System\Form\Builder\Field
* @since 5.2
*/
-class ItemListFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, IMaximumFormField {
+class ItemListFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, IMultipleFormField {
use TAutoFocusFormField;
use TImmutableFormField;
- use TMaximumFormField {
- maximum as protected traitMaximum;
- }
+ use TMultipleFormField;
/**
* @inheritDoc
*/
const SAVE_VALUE_TYPE_SSV = 'ssv';
+ /**
+ * @inheritDoc
+ */
+ public function __construct() {
+ $this->multiple();
+ }
+
/**
* @inheritDoc
*/
return $this->getSaveValueType() !== self::SAVE_VALUE_TYPE_ARRAY;
}
- /**
- * @inheritDoc
- */
- public function maximum($maximum = null) {
- $this->traitMaximum($maximum);
-
- if ($maximum <= 0) {
- throw new \InvalidArgumentException("The maximum number of items has to be positive.");
- }
-
- return $this;
- }
-
/**
* @inheritDoc
*/
*/
public function validate() {
if (is_array($this->getValue())) {
- if ($this->getMaximum() !== null && count($this->getValue()) > $this->getMaximum()) {
+ if ($this->getMinimumMultiples() > 0 && count($this->getValue()) < $this->getMinimumMultiples()) {
$this->addValidationError(new FormFieldValidationError(
- 'maximumItems',
- 'wcf.form.field.itemList.error.maximumItems',
+ 'minimumMultiples',
+ 'wcf.form.field.itemList.error.minimumMultiples',
[
- 'items' => count($this->getValue()),
- 'maximumItems' => $this->getMaximum()
+ 'minimumCount' => $this->getMinimumMultiples(),
+ 'count' => count($this->getValue())
+ ]
+ ));
+ }
+ else if ($this->getMaximumMultiples() !== IMultipleFormField::NO_MAXIMUM_MULTIPLES && count($this->getValue()) > $this->getMaximumMultiples()) {
+ $this->addValidationError(new FormFieldValidationError(
+ 'maximumMultiples',
+ 'wcf.form.field.itemList.error.maximumMultiples',
+ [
+ 'maximumCount' => $this->getMaximumMultiples(),
+ 'count' => count($this->getValue())
]
));
-
- return;
}
$invalidItems = [];
<item name="wcf.form.field.date.error.format"><![CDATA[Der angegebene Wert hat ein ungültiges Format.]]></item>
<item name="wcf.form.field.date.error.earliestDate"><![CDATA[Der angegebene Wert darf nicht früher sein als {$earliestDate}.]]></item>
<item name="wcf.form.field.date.error.latestDate"><![CDATA[Der angegebene Wert darf nicht später sein als {$latestDate}.]]></item>
- <item name="wcf.form.field.itemList.error.maximumItems"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} {#$items} Einträge angegebenen, die Maximalanzahl beträgt jedoch {#$maximumItems}.]]></item>
+ <item name="wcf.form.field.itemList.error.maximumMultiples"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du darfst{else}Sie dürfen{/if} nicht mehr als {#$maximumCount} {if $maximumCount == 1}Eintrag{else}Einträge{/if} angeben, es wurde{if $count != 1}n{/if} aber {#$count} {if $count == 1}Eintrag{else}Einträge{/if} angegeben.]]></item>
+ <item name="wcf.form.field.itemList.error.minimumMultiples"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du musst{else}Sie müssen{/if} zumindest {#$minimumCount} {if $minimumCount == 1}Eintrag{else}Einträge{/if} angeben, es wurde{if $count != 1}n{/if} aber nur {#$count} {if $count == 1}Eintrag{else}Einträge{/if} angegeben.]]></item>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Titelbild]]></item>
<item name="wcf.form.field.date.error.format"><![CDATA[The format of the entered value is invalid.]]></item>
<item name="wcf.form.field.date.error.earliestDate"><![CDATA[The entered value may not be earlier than {$earliestDate}.]]></item>
<item name="wcf.form.field.date.error.latestDate"><![CDATA[The entered value may not be later than {$latestDate}.]]></item>
- <item name="wcf.form.field.itemList.error.maximumItems"><![CDATA[You have entered {#$items} items but the maximum number of items is {#$maximumItems}.]]></item>
+ <item name="wcf.form.field.itemList.error.maximumMultiples"><![CDATA[You may not enter more than {#$maximumCount} {if $maximumCount == 1}entry{else}entries{/if} but {#$count} {if $count == 1}entry is{else}entries are{/if} given.]]></item>
+ <item name="wcf.form.field.itemList.error.minimumMultiples"><![CDATA[You have to entered at least {#$minimumCount} {if $minimumCount == 1}entry{else}entries{/if} but only {#$count} {if $count == 1}entry is{else}entries are{/if} given.]]></item>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Cover Photo]]></item>