JavaScript Polymer v1.0 input validation on button click polymer input validation,polymer field validation,polymer paper-input validation,

Noob at polymer here, so please bear with me.

I'm trying to learn how to create a form, one that requires the user to input text into a textbox, before hitting "Submit". Should the user hit "Submit" without anything in the textbox, the textbox is highlighted red, and displays an error message, etc.

Here's my code (no validation yet) so far:

<dom-module id="accountability-ticket">
    <template>
        <paper-dialog with-backdrop entry-animation="scale-up-animation" exit-animation="fade-out-animation" id="diagTicket">
            <h2>I Own It Ticket</h2>
            <div>
                <paper-input-container id="gcashDeco" required error="GCash Ref. Required">
                    <input id="gcashText" is="iron-input">
                </paper-input-container>
                <div class="ctrlButtons flex">  
                    <paper-button dialog-dismiss>Cancel</paper-button>
                    <paper-button on-click="confirmClick">Submit</paper-button>
                </div>
            </div>
        </paper-dialog>
    </template>
</dom-module>
<script>
Polymer({
    is: "accountability-ticket",
    confirmClick: function(event){
        console.log(event);
        var gCashDeco = document.getElementById('gcashDeco');
        var gCashText = document.getElementById('gcashText');   
    }
});

</script>

I've been reading the Polymer documentation, and so far came up with two things:

  1. <paper-input> doesn't validate, per se, according to v0.5 - It must be wrapped in <paper-input-decorator> first.
  2. Version 1.0 is even less clear than that, with <paper-input-container> instead of <paper-input-decorator>, and mixed tags in the demo pages.

Given that I want to stick with the latest version (v1.0), what do I need to add to my code to get it to check if the textbox is empty, and display an error message if it is?

Thanks.

Answer:1

Yep, the Polymer docu is somewhat confusing, but as a general rule of thumb: always have a look at the behaviours the element is equiped with.

So, paper-input (in 1.0) comes with PaperInputBehavior and this implies that you can simply write the following:

<paper-input label="Input label" required error-message="Field required!"></paper-input>

<paper-input label="Input label" minlength="4" maxlength="10" auto-validate></paper-input>

<paper-input label="Input label" pattern="MY_REGEX" auto-validate></paper-input>

<paper-input label="Input label" validator="myvalidator"></paper-input>

auto-validate makes the input – of course – validate as it is being typed into. myvalidator must be an element implementing the IronValidatorBehavior and inserted somewhere on the page. If you don't want the fields to be auto-validating or wanna do it yourself, call validate() on that field or set the invalid-flag and the error message will be shown. You can even adjust the message programmatically.

Answer:2

I have been working with a page that redirects a user to either an installed application or a webpage (the fallback). This is called when the page first loads via ClientScript.RegisterStartupScript; ...

I have been working with a page that redirects a user to either an installed application or a webpage (the fallback). This is called when the page first loads via ClientScript.RegisterStartupScript; ...

  1. settimeout redirect not working

I'm trying to send a simple message from a form to my server using socket.io. Sadly enough this is failing, I know the client has a connection with the server, but it does not appear to receive the ...

I'm trying to send a simple message from a form to my server using socket.io. Sadly enough this is failing, I know the client has a connection with the server, but it does not appear to receive the ...

  1. socket.io send form data
  2. socket.io send form

function rolldice() { var x = Math.floor(Math.random() * ((6 - 1) + 1) + 1); var y = Math.floor(Math.random() * ((6 - 1) + 1) + 1); var dicetotal = x + y; var double = 0; $('.dice1'...

function rolldice() { var x = Math.floor(Math.random() * ((6 - 1) + 1) + 1); var y = Math.floor(Math.random() * ((6 - 1) + 1) + 1); var dicetotal = x + y; var double = 0; $('.dice1'...

  1. dice roll javascript code
  2. dice roll js
  3. 3d dice roll javascript
  4. dice roll animation javascript
  5. dice roll game javascript
  6. roll dice function javascript

I want to build a stream graph from data in a .csv file. I forked http://bl.ocks.org/lgrammel/1935509 to generate the stream graph, but I got stuck loading the data. My JS is below. var n = 8, // ...

I want to build a stream graph from data in a .csv file. I forked http://bl.ocks.org/lgrammel/1935509 to generate the stream graph, but I got stuck loading the data. My JS is below. var n = 8, // ...