-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d618eed
commit 26323fa
Showing
3 changed files
with
55 additions
and
47 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,17 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Data binding</title> | ||
<meta name="author" content="Luis Castro Martín"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" href="https://luiscastro193.github.io/favicon.svg" type="image/svg+xml"> | ||
<script src="framework.js"></script> | ||
</head> | ||
|
||
<body> | ||
<h3>Data binding</h3> | ||
<input type="number" oninput="nInputs.value = this.value" onmouseenter="this.select()" min="1" value="3" > | ||
<br><br> | ||
<section id="inputs"> | ||
</section> | ||
<script> | ||
"use strict"; | ||
var nInputs = new Observable(document.querySelector("input").value); | ||
var message = new Observable("Binded data"); | ||
|
||
function inputElement() { | ||
let element = htmlToElement(`<article> | ||
<input type="text" oninput="message.value = this.value" onmouseenter="this.focus()" style="max-width: 17cm; width: 100%" > | ||
<br><br> | ||
</article>`); | ||
let input = element.querySelector('input'); | ||
input.value = message.value; | ||
message.subscribe(input, () => input.value = message.value); | ||
return element; | ||
} | ||
|
||
function inputsElement() { | ||
let element = htmlToElement(`<section id="inputs"></section>`); | ||
|
||
for (let i = 0; i < nInputs.value; i++) | ||
element.appendChild(inputElement()); | ||
|
||
nInputs.subscribe(element, () => element.replaceWith(inputsElement())); | ||
return element; | ||
} | ||
|
||
document.getElementById("inputs").replaceWith(inputsElement()); | ||
</script> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Data binding</title> | ||
<meta name="author" content="Luis Castro Martín"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" href="https://luiscastro193.github.io/favicon.svg" type="image/svg+xml"> | ||
<script src="main.js" type="module"></script> | ||
</head> | ||
<body> | ||
<h3>Data binding</h3> | ||
<input type="number" min="1" value="3" > | ||
<br><br> | ||
<section id="inputs"></section> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
import {htmlToElement, Observable} from "./framework.js"; | ||
|
||
let mainInput = document.querySelector("input"); | ||
let nInputs = new Observable(mainInput.value); | ||
let message = new Observable("Binded data"); | ||
|
||
function inputElement() { | ||
let element = htmlToElement(`<article> | ||
<input type="text" style="max-width: 17cm; width: 100%" > | ||
<br><br> | ||
</article>`); | ||
let input = element.querySelector('input'); | ||
input.value = message.value; | ||
input.oninput = () => {message.value = input.value}; | ||
input.onmouseenter = () => input.focus(); | ||
message.subscribe(input, () => input.value = message.value); | ||
return element; | ||
} | ||
|
||
function inputsElement() { | ||
let element = htmlToElement(`<section id="inputs"></section>`); | ||
|
||
for (let i = 0; i < nInputs.value; i++) | ||
element.appendChild(inputElement()); | ||
|
||
nInputs.subscribe(element, () => element.replaceWith(inputsElement())); | ||
return element; | ||
} | ||
|
||
mainInput.oninput = () => {nInputs.value = mainInput.value}; | ||
mainInput.onmouseenter = () => mainInput.select(); | ||
document.getElementById("inputs").replaceWith(inputsElement()); |