Skip to content

Request: Add field array helpers (push, pop, splice, etc) #14662

@sillvva

Description

@sillvva

Describe the problem

There's should be an easier way to add, remove, or sort items in a field array than something like this:

<button onclick={() => form.fields.arr.set([...form.fields.arr.value(), ""])}> 
	Add Item 
</button>

<button onclick={() => {
  const values = form.fields.arr.value();
  values.pop();
  form.fields.arr.set(values)
}> 
	Remove Last Item 
</button>

https://stackblitz.com/edit/array-methods-308957?file=src%2Froutes%2Ftest.remote.js,src%2Froutes%2F%2Bpage.svelte,package.json

Describe the proposed solution

Array methods:

<button onclick={() => form.fields.arr.push("")}> 
	Add Item 
</button>

<button onclick={() => form.fields.arr.pop()}> 
	Remove Last Item 
</button>

Alternatives considered

Helper functions or a class with static methods

<button onclick={() => push(form.fields.arr, "")}> 
	Add Item 
</button>

<button onclick={() => FieldArr.pop(form.fields.arr)}> 
	Remove Last Item 
</button>

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions