
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
A simple, lightweight, and no-dependency library for repeating elements with a button click. Useful for input groups in forms that need to be repeated so the user can submit an arbitrary number of items.
A simple, lightweight, and no-dependency library for repeating elements with a button click. Useful for input groups in forms that need to be repeated so the user can submit an arbitrary number of items.
npm install @kennedyrose/repeatable
or
yarn add @kennedyrose/repeatable
<ul>
<li class="person-template">
<input name='people[][firstName]' placeholder='First Name' />
<input name='people[][lastName]' placeholder='Last Name' />
<button class="remove-person">Remove person</button>
</li>
</ul>
<button class="add-person">Add person</button>
import Repeatable from '@kennedyrose/repeatable'
new Repeatable({
template: `.person-template`,
button: `.add-person`,
removeButton: `.remove-person`,
incrementInputs: true,
})
If you want to show a message when there are no elements, you can pass an emptyState option. It accepts either a query selector string or an element. This element will show when there are no elements and hide when there are.
<div class="empty-state">No people added yet.</div>
new Repeatable({
// ...
emptyState: `.empty-state`,
})
Set startEmpty to true to start with no elements and an empty state.
new Repeatable({
// ...
startEmpty: true,
})
Set min and max to limit the number of elements that can be added. If min is set, the remove button will be disabled when there are fewer than that number of elements. If max is set, the add button will be disabled when there are more than that number of elements.
new Repeatable({
// ...
min: 3,
max: 6,
})
You can pass functions to onCreate and onRemove to run when an element is created or removed. The element that was added or removed gets passed so you can manipulate the value, name attribute, etc.
new Repeatable({
// ...
onCreate: (element) => {
console.log(`Added element:`, element)
},
onRemove: (element) => {
console.log(`Removed element:`, element)
},
})
If you have multiple repeatable elements on the same page, you can set incrementInputs to true to increment the [] part of the name attributes in all inputs in the template. This is useful if you want to submit the data as an array of objects.
<ul>
<li class="person-template">
<input name='people[][firstName]' placeholder='First Name' />
<input name='people[][lastName]' placeholder='Last Name' />
<button class="remove-person">Remove person</button>
</li>
</ul>
new Repeatable({
// ...
incrementInputs: true,
})
FAQs
A simple, lightweight, and no-dependency library for repeating elements with a button click. Useful for input groups in forms that need to be repeated so the user can submit an arbitrary number of items.
The npm package repeatable receives a total of 1 weekly downloads. As such, repeatable popularity was classified as not popular.
We found that repeatable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.