2

Hi all I want to fetch the input value from Buyer_name into Copied Buyer_name input field.i tried many ways but unable to find the solution if anyone knows the solution please help me....my plunk

controller:-

$('#supname').change(function() {
$('#supnamecopy').val($(this).val());

});

Html:-

 <label for="quantity">Quantity</label>
      <input type="text" ng-model="state.quantity" id="quantity" typeahead="state as state.quantity for state in states | filter: $viewValue">

 <label for="quantity">Buyer_name</label>
      <input type="text" id="supname" ng-model="state.quantity" typeahead="state.buyer_name  for state in states | filter: $viewValue">

 <label for="quantitycopy">Copied Buyer_name</label>
      <input type="text" name="supnamecopy" id="supnamecopy" ng-model="copied">

My Data:-

    $scope.states = [{
"_id": "5744009c2f0f2bef0ca707ef",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"description_count": "check",
"description_quality": "new",
"__v": 1,
"created": "2016-05-24T07:19:56.471Z",
"cone": "pending",
"status": "pending",
"currency": "Rs",
"unit": "KG",
"price": [
"500",
"400"
],
"actual_devlivery_date": "2016-05-2",
"ex_india_date": "2016-05-24",
"quantity_unit": "KG",
"quantity": "34",
"enquiry_received_date": "2016-05-24",
"supplier_name": "Mani selvam",
"buyer_name": "Rohit"
},
R. Mani Selvam
  • 320
  • 8
  • 36

2 Answers2

1

http://plnkr.co/edit/VIZkyM08IKuSChL5vvOL?p=preview

HTML - remains as is

JS - changed jQuery to angular functionality.

The way your ng-model is set at the moment assigns the $scope.state.quantity as the selected state rather than the quantity value from that state.

$scope.$watch('state.quantity', function() {
    if($scope.state && $scope.state.quantity && $scope.state.quantity.buyer_name) {
        $scope.copied = angular.copy($scope.state.quantity.buyer_name);
    } else {
        $scope.copied = null;
    }
});
Marcus Höglund
  • 16,172
  • 11
  • 47
  • 69
Rian O'Dwyer
  • 435
  • 2
  • 12
  • thank you for your answer!!! .......actually i was used type ahead in quantity, if i select quantity value simultaneously the buyer name need fetch and need copied buyer_name values also.....[my plunk] (plnkr.co/edit/yZ8h2G1BDolfwrkGkP4F?p=preview) please help me for the same..... for example:- if i select quantity is 34, buyer_name is fetched automatically Rohit.....what i exactly need the buyer_name input need to fetch into copied buyer_name also.... – R. Mani Selvam Jun 28 '16 at 12:00
  • Updated answer above to meet your needs I think – Rian O'Dwyer Jun 28 '16 at 12:01
  • Hi Rian if you able to provide the plunker which is easily (helpful and understand) to me..!!!! – R. Mani Selvam Jun 28 '16 at 12:07
  • The link is at the top of the answer – Rian O'Dwyer Jun 28 '16 at 12:08
  • @R. Mani Selvam. You're welcome. Please tick the answer if it solved your issue – Rian O'Dwyer Jun 28 '16 at 12:17
  • i have the same issues with different set of data pls look at this link(http://plnkr.co/edit/gfNKpAdmnxFhJRyLFq1e?p=preview). pls help me with this issue. thanks – R. Mani Selvam Jun 28 '16 at 13:49
  • please follow this link as well :- (http://stackoverflow.com/questions/38078410/how-can-i-fetch-the-value-from-one-input-field-into-another-field) – R. Mani Selvam Jun 28 '16 at 14:05
0

try this. this shall give you a live preview of the copy as well

<label for="quantity">Buyer_name</label>
      <input type="text" id="supname" ng-model="state.quantity" typeahead="state.buyer_name  for state in states | filter: $viewValue">

 <label for="quantitycopy">{{state.quantity}}</label>
      <input type="text" name="supnamecopy" id="supnamecopy" ng-model="copied">
mattyman
  • 351
  • 2
  • 16