Basic Array Usage
To work with arrays, accessfield.state.value on an array field and use Lit’s repeat directive to render items.
Simple Array Example
Adding Items to Arrays
Use thepushValue method to add new items to an array field:
pushValue, the list re-renders with the new item.
Accessing Nested Fields
Access individual array items using bracket notation in the field name:Complete Array Example
Here’s a full example with adding items and nested field access:Array Field Methods
The field API provides several methods for managing arrays:pushValue(item)
Add an item to the end of the array:removeValue(index)
Remove an item at a specific index:insertValue(index, item)
Insert an item at a specific position:replaceValue(index, item)
Replace an item at a specific index:swapValues(indexA, indexB)
Swap two items in the array:moveValue(from, to)
Move an item from one index to another:Array with Remove Buttons
Add remove buttons to let users delete individual items:Validating Array Fields
You can validate both the array itself and individual array items:Array-Level Validation
Validate the entire array:Item-Level Validation
Validate individual array items:Complex Nested Objects
Arrays can contain complex objects with multiple fields:Using the repeat Directive
Lit’srepeat directive is essential for efficiently rendering array items. The second parameter provides a key for tracking items:
Next Steps
- Learn more about Form Validation for arrays
- Check the API Reference for all field methods
- Explore Basic Concepts for deeper understanding