This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>Email input demo</title> | |
</head> | |
<body> | |
<script type="module" src="../email-input-vanilla-module/email-input.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const template = document.createElement('template'); | |
template.innerHTML = ` | |
<label for="email-input">Email</label> | |
<input type="text" id="email-input" name="email-input"> | |
<div> | |
<small style="visibility: hidden;" id="validationtext"></small> | |
</div> | |
<style> | |
.invalid { | |
color: red; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.customElements.define('email-input', EmailInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connectedCallback() { | |
//Registration of the ShadowDOM | |
this.attachShadow({ mode: 'open' }); | |
const instance = template.content.cloneNode(true); | |
this.shadowRoot.appendChild(instance); | |
//Getting a reference to the input-field and the element which will contain the validation text | |
const emailInput = this.shadowRoot.getElementById('email-input'); | |
const validationText = this.shadowRoot.getElementById('validationtext'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get validmessage() { | |
return this.getAttribute('validmessage'); | |
} | |
set validmessage(val) { | |
this.setAttribute('validmessage', val) | |
} | |
get invalidmessage() { | |
return this.getAttribute('invalidmessage'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const template = document.createElement('template'); | |
template.innerHTML = ` | |
<!--Label that will display the input-title 'Email'--> | |
<label for="email-input">Email</label> | |
<!--Input field that will be validated when it loses focus--> | |
<input type="text" id="email-input" name="email-input"> | |
<!--Container for the validation text, hidden by default--> | |
<div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCustomParagraph extends HTMLElement { | |
constructor() { | |
super(); | |
} | |
//all the properties and methods | |
} | |
window.customElements.define('my-custom-paragraph', MyCustomParagraph); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="module" src="my-custom-paragraph/my-custom-paragraph.js"></script> | |
<!--once imported, you can use the WebComponent as a native HTML-element--> | |
<my-custom-paragraph></my-custom-paragraph> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$container = document.getElementById("custom-paragraph-containter"); | |
$container.attachShadow({mode: 'open'}); | |
$container.shadowRoot.appendChild((document.getElementById('custom-paragraph').content).cloneNode(true)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Paragraph outside the template!</p> | |
<div id="custom-paragraph-containter"></div> | |
<template id="custom-paragraph"> | |
<style> | |
p { | |
color: white; | |
background-color: #666; | |
padding: 5px; | |
} | |
</style> |
NewerOlder