I'm trying to create my own custom polymer-element that would enforce a specified input mask. I've created this element:
<polymer-element name="phone-input" attributes="phoneNumber">
<template>
<form>
<input id="txtPhoneNumber" type="text" class="field phone-field"
required placeholder="999-999-9999" maxlength="12" value="{{ phoneNumber }}"/>
</form>
</template>
<script type="application/dart" src="phone_input.dart"></script>
</polymer-element>
As you can see, the input field inside my element is marked with the required attribute. So when I put my phone-input element in a form, I expect it to enforce this constrain.
<form name="testForm">
<phone-input id="myPhoneInput"></phone-input>
<button value="" id="btnTest">Test</button>
</form>
However, when I do it this way, I can post the form at will, even if there is no value in my field.
The only way I've managed to make sure that the error message would pop when the field is empty is by including my form and my button in my phone-input polymer element, like this:
<polymer-element name="phone-input" attributes="phoneNumber">
<template>
<form>
<input id="txtPhoneNumber" type="text" class="field phone-field"
required placeholder="999-999-9999" maxlength="12" value="{{ phoneNumber }}"/>
<button value="" id="btnTest">Test</button>
</form>
</template>
<script type="application/dart" src="phone_input.dart"></script>
</polymer-element>
This works, but my initial goal was to create a phone-input element that would work on it's own and could be included in any form...
Do you know if what I'm trying to do is possible at all and if it is, what am I doing wrong? Thanks!