Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Using Django -->
- {% extends 'polymer.html' %} <!-- not related to original polymer -->
- {% block title %} Add {% endblock %}
- {% block pageTitle %} Add Item {% endblock %}
- {% block section %}
- <style type="text/css">
- /* Cut away for brevity */
- </style>
- <section horizontal center-justified layout>
- <div vertical layout class="form">
- <paper-shadow></paper-shadow>
- <form is="ajax-form" method="post" action="/add/go/" id="myform">{% csrf_token %}
- <paper-input placeholder="Item name" floatingLabel required>
- </paper-input>
- <paper-input placeholder="Item Unique Code" floatingLabel required>
- </paper-input>
- <paper-input placeholder="Describe Item" floatingLabel>
- </paper-input>
- <div horizontal layout center>
- <div flex two style="margin-top:10px;"> Stolen or Not</div>
- <div flex one>
- <paper-dropdown selected="Choose" valueattr="label">
- <paper-item icon="blank" label="Choose"></paper-item>
- <paper-item icon="check" label="Yes"></paper-item>
- <paper-item icon="cancel" label="No"></paper-item>
- </paper-dropdown>
- </div>
- </div>
- <div horizontal end-justified layout>
- <input type="submit"> <!-- The submit button -->
- </div>
- </form>
- </div>
- </section>
- <paper-toast id="invalids" role="alert" text="Some form fields are invalid">
- </paper-toast>
- <paper-toast id="thanks" role="alert" text="Thanks! Your choices have been submitted!">
- </paper-toast>
- <paper-toast id="response" role="alert" text="Failed to submit">
- </paper-toast>
- <script>
- (function() {
- var form = document.getElementsByTagName('form')[0]
- form.addEventListener('invalid', function() {
- document.querySelector('#invalids').show()
- });
- form.addEventListener('submitting', function() {
- });
- form.addEventListener('submitted', function(event) {
- if (event.detail.status > 299) {
- document.querySelector('#response').show()
- console.log(even.detail.errors)
- }
- else {
- document.querySelector('#thanks').show()
- }
- });
- }());
- </script>
- {% endblock %}
- Upon Submitting, I get this results in Network > Filters > XHR > Preview in Developer Tools in Chrome:
- description: [This field is required.]
- device: [This field is required.]
- slug: [This field is required.]
- stolen: [This field is required.]
- type_of_item: [This field is required.]
- which is a clear indication that NOTHING is sent. Response from server says BAD REQUEST, and upon looking further, I get the error message of 'this field is required' from server too.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement