Two way binding

Size
2,638 Kb
Views
10,120

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 Previews

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";
Two way binding - Script Codes
Two way binding - Script Codes
Home Page Home
Developer Tamo Tkhlashidze
Username Nagasaki1991
Uploaded January 14, 2023
Rating 3
Size 2,638 Kb
Views 10,120
Do you need developer help for Two way binding?

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!

Tamo Tkhlashidze (Nagasaki1991) Script Codes
Create amazing SEO content with AI!

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!