Bind value from input to properties of an object
Date : March 29 2020, 07:55 AM
may help you . Assuming that shareholderis an object on your 'myController', do this: <div ng-controller="myController as $ctrl">
<input name="shares" ng-model="$ctrl.shareholder.shares" type="number" required />
<input name="name" ng-model="$ctrl.shareholder.name" required />
</div>
$scope.shareholder = {
shares: 'value from input'
name: 'value from input'
}
<input name="shares" ng-model="shareholder.shares" type="number" required />
<input name="name" ng-model="shareholder.name" required />
|
How can i bind input to object in vue.js
Date : March 29 2020, 07:55 AM
Does that help Is there a way to bind input to objects instead of single variables. , you can bind directly to data, code as follow: var demo = new Vue({
el: "#demo",
data: {
user: {
name: "please enter"
}
}
})
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<div id="demo">
<input v-model="user.name">
<span>{{user.name}}</span>
</div>
|
Bind specific index of an observableArray to an input control
Date : March 29 2020, 07:55 AM
this will help Is there a reason you bind the parent div value and then pass $data when you can just provide the value binding directly to the input? var ViewModel = function() {
this.arr = ko.observableArray([
{
"SpecName": "reportingcurrency",
"SpecValue": "EUR"
},
{
"SpecName": "transactionscurrency",
"SpecValue": "GBP"
}
])
};
ko.applyBindings(new ViewModel());
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<div>
<input type="text" data-bind="value: arr()[0].SpecValue" />
</div>
|
Is there any way to bind drop down field options to specific input type in yii2
Date : March 29 2020, 07:55 AM
this will help Add some JavaScript that listens to the change of the dropdown and show/hide your elements based on the selected value. I wrote a small example. You'll have to change the IDs to match your elements and maybe make some other small changes, but something like this should work. <?php
$this->registerJs("
$(function() {
$('#your-form-media-type-id').on('change', function() {
var value = this.value
switch (value) {
case 'text':
$('#your-mce-div').show();
$('#your-image-input-div').hide();
break;
case 'image':
$('#your-image-input-div').show();
$('#your-mce-div').hide();
break;
}
});
});
");
|
Bind HTML element to Javascript object and store object in array - Update object with input value from child element
Date : March 29 2020, 07:55 AM
it should still fix some issue One way to do this is to use a closure. The purpose of a closure is to capture variables from the containing function so those variables can be used later, after the containing function exits. let data = {
nameGenerator: 0
};
function addInput() {
// generate a new name and property in data object
let propertyName = String.fromCharCode("a".charCodeAt() + data.nameGenerator++);
// initialize property value to its name
data[propertyName] = propertyName;
// add <div><input value="(property)"></div> to container
let containerElement = document.getElementById("container");
let lineElement = document.createElement("div");
let inputElement = document.createElement("input");
lineElement.appendChild(inputElement);
containerElement.appendChild(lineElement);
// initialize input value (note: this does not bind the two, just initializes)
inputElement.value = data[propertyName];
// create a closure that binds the property to the element
inputElement.addEventListener("keyup", function () {
// inside this function, propertyName and inputElement
// are "captured" in the closure
data[propertyName] = inputElement.value;
})
}
|