Skip to content

Conversation

sillvva
Copy link

@sillvva sillvva commented Oct 9, 2025

Fixes #14662 ("Implements")

  • Adds type RemoteFormArrayFieldMethods<T> type and intersects it to RemoteFormFieldContainer and RemoteFormField
    • Adds .push(), .pop(), .unshift(), .shift(), .splice(), and .sort() methods to field arrays
  • Exports RemoteFormFields type to allow the creation of custom field array wrapper functions and components
  • Adds docs
  • Adds test

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

Mutating field arrays

Field arrays should have the following extra methods to mutate the array: .pop(), .push(), .shift(), .unshift(), .splice(), and .sort(). Other array methods and properties can still be accessed through the .value() method.

<script>
	import { cart } from '../data.remote';

	// add to cart
	cart.fields.items.push({
		sku: "SKU12345",
		name: "TV Set",
		price: 1200,
		quantity: 1
	});

	// remove item at index `i`
	cart.fields.items.splice(i, 1);
	
	// cart total
	cart.fields.items.value().reduce((acc, item) => acc + item.price * item.quantity, 0);
</script>

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Oct 9, 2025

🦋 Changeset detected

Latest commit: 26e0e0c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

- The previous example could have been achieved simply by `cart.fields.items.set([])`
@sillvva
Copy link
Author

sillvva commented Oct 10, 2025

Not sure why that one test is timing out. It started after a change to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant