Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <my-form ng-app="CreateApp" ng-controller="mainController">
  2.  
  3. <form ng-submit="submitForm()" novalidate>
  4. <fieldset>
  5. <div ng-repeat="field in result.fields">
  6. <label for="{{field.type}}">{{field.label}}</label>
  7. <input type="{{field.type}}" ngRequired="{{field.required}}">
  8. <span ng-show="{{field.errorMessages}}"></span>
  9. </div>
  10.  
  11. <!-- not sure how to display the answers options and validate them -->
  12. <input type="{{answer.type}}" name="{{answer.label}}" ngRequired="{{answer.required}}" />
  13.  
  14.  
  15. </fieldset>
  16.  
  17. <button type="button" ng-click="onValidate(); return false;"> Validate</button>
  18. <button type="submit"> Submit </button>
  19. </form>
  20.  
  21. </my-form>
  22.  
  23. var myApp=angular.module('CreateApp', []);
  24.  
  25. myApp.controller('mainController', function($scope, $http) {
  26. $http.get('form.json').success(function(response) {
  27. $scope.result = response;
  28. console.log($scope.fields);
  29. });
  30.  
  31. // function to submit the form after all validation has occurred
  32. $scope.submitForm = function() {
  33.  
  34. // check to make sure the form is completely valid
  35. if ($scope.userForm.$valid) {
  36. alert('our form is amazing');
  37. }
  38.  
  39. };
  40.  
  41. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement