Advertisement
Guest User

aurelia_dynamic_form

a guest
Apr 19th, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. Thomas Shipley @tdshipley 11:13
  2. Woops deleted the message when all I wanted to do was fix a typo :(
  3. Sorry for the spam...
  4. I have a form which has a section which might contain some fields or not based on if a test has some input values. To manage this I have a array on a view model object which when the user wants to add a test input they click a button to add a new empty one to the array:
  5. addTestInput() {
  6. this.vm.test.testInputs.push({
  7. argumentName: "",
  8. valueType: "",
  9. value: ""
  10. });
  11. }
  12. Then in the UI I loop over each object in the array and create form elements to edit the objects properties.
  13. <template if.bind="vm.test.testInputs.length > 0" repeat.for="testInput of vm.test.testInputs">
  14. <div class="form-group">
  15. <label for="testInputArgumentName${$index}">Argument Name</label>
  16. <input value.bind="testInput.argumentName" type="text" class="form-control" id="testInputArgumentName" placeholder="Argument Name">
  17. </div>
  18.  
  19. /* More fields ...*/
  20. This works when the user first presses the add test input button. A test input object is added to the array and the fields for it are shown in the UI. But when I press the button for the second time a second object is added to the array. But additional fields for the new object are not added to the UI. I have read http://blog.williamhayes.org/2015/08/dynamic-input-list-in-aurelia.html but I don't seem to be able to get it working. Anyone have any ideas - they would be greatly appreciated :)
  21.  
  22. Jason Sobell @jsobell 11:13
  23. @tdshipley What happens if you add something like
  24. get testInputs() { return vm.test.testInputs; }
  25. and run it against that? The array tracking stuff tends to be troublesome, so I don't know if that might help or not, but try the whole thing with a simple array at the VM level instead of nested in an object
  26.  
  27. Jason Sobell @jsobell 11:19
  28. Oh, and id="testInputArgumentName" should say id="testInputArgumentName${$index}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement