Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@swup/forms-plugin
Advanced tools
A swup plugin for submitting forms.
form[data-swup-form]
Note: This plugin is meant for simple scenarios like search or contact forms. For complex requirements like custom serialization, it is recommended to use the swup API directly.
Install the plugin from npm and import it into your bundle.
npm install @swup/forms-plugin
import SwupFormsPlugin from '@swup/forms-plugin';
Or include the minified production file from a CDN:
<script src="https://unpkg.com/@swup/forms-plugin@3"></script>
To run this plugin, include an instance in the swup options.
const swup = new Swup({
plugins: [new SwupFormsPlugin()]
});
Action, method and encoding type attributes set on the form are respected.
The server response must be a valid page with all containers to be replaced by swup.
The plugin respects custom animations set on the form using the data-swup-animation
attribute:
<!-- Animate with an 'overlay' custom animation -->
<form action="/" data-swup-form data-swup-animation="overlay"></form>
If you give a form an additional attribute [data-swup-inline-form]
, swup will:
containers
.Note If you mark a form as an inline form, the form must have an
id
attribute
HTML
<form id="form-1" class="transition-form" data-swup-form data-swup-inline-form method="POST">
<input name="test"></input> <input type="submit"></input>
</form>
CSS
.transition-form.is-changing {
transition: opacity 200ms;
}
.transition-form.is-animating {
opacity: 0;
}
formSelector
Type: String
, Default: form[data-swup-form]
Customize the selector for forms which should be handled by swup.
inlineFormSelector
Type: String
, Default: form[data-swup-inline-form]
Customize the selector for inline forms
stripEmptyParams
Type: Boolean
, Default: false
Strip empty parameters from forms with action="GET"
before submitting.
?foo=&bar=baz&bat=
?bar=baz
The plugin adds two new hooks to swup.
form:submit
Triggered when a form is submitted.
swup.hooks.on('form:submit', (visit, { el, event }) => {
console.log(el);
});
form:submit:newtab
Triggered when a form is submitted to a new tab or window. This will happen if the user
has pressed either the Command
(Mac), Control
(Windows) or Shift
key while submitting
the form. The plugin normalizes that behavior across browsers.
[3.6.0] - 2024-07-19
#hash
FAQs
A swup plugin for submitting forms
The npm package @swup/forms-plugin receives a total of 2,050 weekly downloads. As such, @swup/forms-plugin popularity was classified as popular.
We found that @swup/forms-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.