Two way binding
How do I make an two way binding?
What is a two way binding? How do you make a two way binding? This script and codes were developed by Tamo Tkhlashidze on 14 January 2023, Saturday.
Two way binding - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>two way binding</title>
</head>
<body> y <form>
firstname <input type="text" data-bind="givi"/>
<div> lastname <input type="text" data-bind="lastname"/>
</div>
</form> <script src="js/index.js"></script>
</body>
</html>
Two way binding - Script Codes JS Codes
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Model = function () { function Model() { _classCallCheck(this, Model); this.obj = {}; } Model.prototype.proxy = function proxy() { console.log(this.obj); }; Model.prototype.getBind = function getBind(element) { var _this = this; var inputs = element.querySelectorAll('[data-bind]'); for (var _iterator = inputs, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var input = _ref; var dataBind = input.getAttribute('data-bind'); this.obj[dataBind] = input.value; input.addEventListener("input", function (event) { var dataAttr = event.target.getAttribute('data-bind'); _this.obj[dataAttr] = event.target.value; }); } var p = new Proxy(this.obj, { set: function set(target, prop, val) { debugger; target[prop] = val; for (var _iterator2 = inputs, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { var _ref2; if (_isArray2) { if (_i2 >= _iterator2.length) break; _ref2 = _iterator2[_i2++]; } else { _i2 = _iterator2.next(); if (_i2.done) break; _ref2 = _i2.value; } var input = _ref2; var dataBind = input.getAttribute('data-bind'); if (dataBind === prop && input.value != val) { input.value = val; } } return true; } }); return p; }; return Model;
}();
var model = new Model();
var obj = model.getBind(document.querySelector('form'));
obj["lastname"] = "tkhlashidze";
obj["firstname"] = "tamo";
Developer | Tamo Tkhlashidze |
Username | Nagasaki1991 |
Uploaded | January 14, 2023 |
Rating | 3 |
Size | 2,638 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Repeater | 2,561 Kb |
Csv to table | 2,333 Kb |
D3 intro | 2,881 Kb |
Audio test | 1,798 Kb |
A Pen by Tamo Tkhlashidze | 2,570 Kb |
Sticky footer | 2,353 Kb |
Generate dic.dictionaryitems insert script from cvs file | 1,972 Kb |
Custom stack class js | 1,970 Kb |
D3 bar chart with svg | 3,071 Kb |
Svg | 1,985 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Speech bubbles | Something | 1,547 Kb |
Tic Tac Toe | Volv | 4,862 Kb |
Animated SVG stroke-dasharray | Netsi1964 | 3,179 Kb |
Growing Root - Scroll control - CANVAS | Cjonasw | 2,342 Kb |
A Different Type of Gallery | DonPage | 2,950 Kb |
Flat UI - Checkbox FIX | ARS | 2,663 Kb |
Eunice A | Ejbronze | 2,203 Kb |
TweetBox with React JS | J0zelito | 3,325 Kb |
Coming Soon | MariamMassadeh | 1,680 Kb |
A Pen by Miro Olma | Programiro | 2,342 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!