1

HTML5 introduce new kinds of input like: number, color, datetime. AngularJS is bundled with polyfills for some of them.

I am looking for some usable method to create custom type of input, using Web Components or another standardized part of HTML. There is already anwser for AngularJS, but I do not want use any external libruary.

UPD:

Examples of custom types taken from HTML5.

  • Types with custom validation like email and tel.
  • Types with different view like date and datetime.
  • Types with custom semantic and/or style like search.
4
  • Would you please provide an example of a custom input type? What purpose does it provide? In my opinion, I think it's for validation purpose and easy filtering. Which in most cases will require an external library to process Commented Mar 22, 2014 at 9:32
  • If want to use a specific type that you created, then I think you will need to provide your own script to validate it as well. Besides, only one or two browsers actually support the new input types, such as Chrome, while Firefox doesn't! Commented Mar 22, 2014 at 9:55
  • @Joraid "you will need to provide your own script to validate it as well." Of course. Commented Mar 22, 2014 at 9:58
  • @Joraid "Besides, only one or two browsers actually support the new input types" It will change. Commented Mar 22, 2014 at 10:03

2 Answers 2

1

Using Web Compontents, you can define a Custom Element that will extend the HTMLInputElement prototype.

This tutorial shows a (very basic) example:

var XComponent = document.registerElement('x-component', {
  extends: 'input',
  prototype: Object.create(HTMLInputElement.prototype)
});
Sign up to request clarification or add additional context in comments.

Comments

0

But just simply add your own attribute.

<input type="custom" name="reg_code" /> 

And thin have javascript to validate that for you.

Or, you can use the pattern attribute to specify your own input type as showed here

Example:

<input type="text" type="tel" pattern="[0-9]{9}">

And

<input type="email" title="E-mail format required" pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$" required="" id="email" name="email">

Update: a new custom input type called Registration Code to follow the format WEK070605

  <input  pattern="[A-Z]{3}[0-9]{6}" required ">

2 Comments

It is defenetly not that I am looking for. You can not create input type with completly different look and/or behaviour the way you have posted.
yeah it seems I misunderstood your question. Different look and behavior? like not a text input? would you please provide an example or full scenario on how this kind of custom input would behave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.