0

How would i hide input elements and replace there value to the table rows , the inputs are dynamically created with push see below code :

view

ID LIKE TO REPLACE THE INPUTS WITH THE VALUE OF INPUTS IN THE TABLE ROWS

<tr class="odd gradeX" ng-repeat="choice in vm.choices">
   <td><a href="" ng-click="vm.addNewChoice()">Add</a></td>
   <td><a href="" ng-click="vm.saveChoice()">save</a></td>
   <td>
    <div class="form-group">
       <div class="input-group">
         <input type="text" placeholder="Item Name" class="form-control" ng-model="choice.item_name"/>
       </div>
    </div>

</td>
<td>
  <div class="form-group">
     <div class="input-group">
       <select data-ng-options='t.value as t.label for t in vm.invoice_item_type' ng-model="choice.item_type" >
        </select>
     </div>
  </div>
</td>

contoller

vm.choices  = [];

vm.addNewChoice = function() {
   var newItemNo = parseInt(vm.choices.length+1);
   vm.choices.push({});
};


vm.saveChoice = function() {
          var lastItem = vm.choices.length-1;
          ------ What to do here ------
         };
2
  • If you could clarify - you want new (not saved) values to be presented using inputs and saved values simply printed in the table row? Commented Dec 16, 2015 at 18:23
  • I want the saved values in vm.choices object to be presented as plain table data ie <td> VALUE OF INPUT </td> Commented Dec 16, 2015 at 18:33

1 Answer 1

1

Ok, the easiest way to do this would be probably something like this:

  1. Add additional field to every choice object saying if it's saved or not
  2. Add two <td>s for every choice, one with plain text and one with input and show/hide them depending on extra parameter' value.

Something like this:

<tr class="odd gradeX" ng-repeat="choice in vm.choices">
   <td><a href="" ng-click="vm.addNewChoice()">Add</a></td>
   <td><a href="" ng-click="vm.saveChoice(choice)">save</a></td>
   <td ng-hide="choice.saved">
    <div class="form-group">
       <div class="input-group">
         <input type="text" placeholder="Item Name" class="form-control" ng-model="choice.item_name"/>
       </div>
    </div>
   </td>
  <td ng-show="choice.saved">
    <div class="form-group">
       <div class="input-group">
         <input type="text" placeholder="Item Name" class="form-control" ng-model="choice.item_name"/>
       </div>
    </div>
   </td>
   <!-- rest of your row goes here -->
</tr>

And in controller:

vm.choices  = [];

vm.addNewChoice = function() {
   var newItemNo = parseInt(vm.choices.length+1);
   vm.choices.push({}); // we don't need to set `saved` property explicitly since undefined will be resolved to false
};


vm.saveChoice = function(choice) {
          var lastItem = vm.choices.length-1;
          choice.saved=true;
          // probably some extra logic related to saving 
};

Note that I've added parameter to saveChoice method - you need to know which choice to save. Also, I think that button for adding new choice should be moved outside of the table - adding new item is not related to any existing item.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.