When utilizing the Polymer tag, there is a dedicated method in Polymer for handling forms called iron-form
. While @Caelan's approach is valid, it may not be compatible with Polymer elements or custom elements like paper-input
and paper-checkbox
. Refer to the Paper Elements page for a comprehensive list of customized inputs.
The <iron-form></iron-form>
component provides the convenient methods serialize
and validate
, ideal for gathering all inputs, including custom elements, with just one function call.
For more details, visit the iron-form.serialize documentation.
var form = document.querySelector('iron-form')
form.onsubmit = function(event) {
event.preventDefault();
var data = form.serialize()
// Handle data accordingly
// return false; // an alternative to event.preventDefault()
}
Check out the discussion on preventDefault vs return false on Stack Overflow – either method will suffice if event bubbling is unimportant in your scenario.