Closed Naehs closed 8 years ago
I have seen the same issue. I solved it by using the iron-form only for the layout and validation, then I use a a11n-keys to catch the enter button and the submit to define my own on-tap handler then send the form using iron-ajax. I find it rather cumbersome, but it works.
Hi Eitch,
Oeffff, yes it seems to be a bit hard for a Framework supposed to be simple on use. But thanks for sharing, i hope there is a simpler solution.
Loïc.
Absolutely! I just needed a solution now and was too lazy to file an issue =)). Hope the team can point us in the right direction...
If you declare your methods in a script alone like that, it is a global script with no link to the element, you want to declare the methods in the Polymer() call for proper scoping.
This worked with no errors for me: (EDIT: Made it a bit more readable.)
<!-- You don't need to load webcomponents.js here, it's loaded in the index.html if needed -->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-form/iron-form.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="shared-styles.html">
<dom-module id="my-view2">
<template>
<!-- Style includes shared-styles which are defined in src/shared-styles.html, eg .card -->
<style include="shared-styles">
:host {
display: block;
padding: 10px;
}
.output {
display: inline-block;
margin: 5px;
}
</style>
<!-- .card class is similar to paper-material, the white background with shadow -->
<div class="card">
<form is="iron-form" method="get" action="/" id="presubmit">
<paper-input name="name" label="Name" value="Batman" required></paper-input>
<!-- on-tap adds an event for methods defined within the element.
Use function name eg. _submit, NOT _submit() -->
<paper-button raised on-tap="_submit">Submit</paper-button>
<paper-button raised on-tap="_reset">Reset</paper-button>
<div class="output"></div>
</form>
</div>
</template>
<script>
Polymer({
is: 'my-view2',
// ready() is called when element is ready at load time.
ready() {
// this.$.elementID allows easy selection of elements within own element.
this.$.presubmit.addEventListener('iron-form-presubmit', function(event) {
this.request.params['sidekick'] = 'Robin';
});
this.$.presubmit.addEventListener('iron-form-submit', function(event) {
// Changed from this.QS to Polymer.dom(this.root).QS to prevent potential conflicts later,
// as this only selects an element from my-view2.
Polymer.dom(this.root).querySelector('.output').innerHTML = JSON.stringify(event.detail);
});
},
_submit(event) {
Polymer.dom(event).localTarget.parentElement.submit();
},
_reset(event) {
var form = Polymer.dom(event).localTarget.parentElement
form.reset();
form.querySelector('.output').innerHTML = '';
}
});
</script>
</dom-module>
Hi Jsilvermist,
Well it's working for me too now :) So i suppose for all the examples on the demo i have to change the "onclick" by "on-tap" and put the script inside the Polymer call.
Thank you for taking the time to help me.
Loïc.
No problem, edited the answer with comments explaining all the things I changed and why.
Also, you reopened this issue, not sure if this was on purpose or not so just wanted to let you know!
Thanks again, It's the first time i close an issue on Github.
So i discovered that "Close issue" close directly the issue but i was waiting a last answer that i just had so i reopened it !
Now i can close it.
Loïc.
Yay, glad you sorted this out :)
I folks, i'm new with Polymer and the Starter-Kit is perfect for the Application that i want to realise. But when i want to add an Iron-Form (the Iron-Form-Presubmit demo) it says in the browser console :
Uncaught ReferenceError: presubmit is not defined
For example i create a new project :
I add the components :
Then i just change the second view "src/my-view2.html" :
To :
Then i run the server :
And i get the following error :
Uncaught ReferenceError: presubmit is not defined
I think the error is related to JQuery but i'm not sure and i don't know how to resolve it, i'm on it since some days...
I need your help !
Greetings Loïc.