Frank Vèssia Posted February 25 Posted February 25 HEllo, I managed to add a field inside a repeater via api but it's added as last element. I cannot find a way to change the position. this is my function protected function addFieldToRepeater(Field $field, $repeaterName) { $fieldgroups = $this->wire('fieldgroups'); $repeaterFg = $fieldgroups->get("repeater_variations"); if(!$repeaterFg) { $this->error("Fieldgroup 'repeater_variations' non trovato."); return; } try { if(!$repeaterFg->getField($field->name)) { $repeaterFg->add($field); $repeaterFg->save(); } else { $this->message(The field is already present."); } } catch (Exception $e) { $this->error("Error: " . $e->getMessage()); } }
Frank Vèssia Posted February 25 Author Posted February 25 10 minutes ago, zoeck said: You mean something like this? No, I need to sort the fields of the repeater not the values created
elabx Posted February 25 Posted February 25 Try: $reference = $repeaterFg->get('field_as_reference') // Or insertBefore() $repeaterFg->insertAfter($field, $reference); $repeaterFg->save() 1
Frank Vèssia Posted February 25 Author Posted February 25 22 minutes ago, elabx said: Try: $reference = $repeaterFg->get('field_as_reference') // Or insertBefore() $repeaterFg->insertAfter($field, $reference); $repeaterFg->save() YES! Thank you 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now