Hi there,
Is there is a built-in way to prevent duplicates when it comes to the Repeater field type?
The Repeater I have setup contains two fields: one is a select list of other Pages and the second is just a text field. Ideally, I'd love the select list of Pages to work similarly to how the Fields list in Admin works. As you're adding Fields to a Template, the ones you've already added become disabled in the list so they cannot be added again.
If that's not possible, then would something like the following be the next best solution as a module?
public function init() {
$this->addHookAfter("InputfieldRepeater::processInput", $this, "validateNoDups");
}
public function validateNoDups($event){
$field = $event->object;
if($field->name == "technical_specs"){
$page = $this->modules->ProcessPageEdit->getPage();
$specs = $page->get("$field->name");
$s = array();
foreach($specs as $spec) {
if ($spec->technical_spec) {
$s[] = $spec->technical_spec->title;
}
}
$dups = $this->get_duplicates($s);
if ($dups) {
$field->error("You have duplicate technical specs: " . implode(', ', $dups));
}
}
}
Thanks!
Lauren