Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <my-form ng-app="CreateApp" ng-controller="mainController">
- <form ng-submit="submitForm()" novalidate>
- <fieldset>
- <div ng-repeat="field in result.fields">
- <label for="{{field.type}}">{{field.label}}</label>
- <input type="{{field.type}}" ngRequired="{{field.required}}">
- <span ng-show="{{field.errorMessages}}"></span>
- </div>
- <!-- not sure how to display the answers options and validate them -->
- <input type="{{answer.type}}" name="{{answer.label}}" ngRequired="{{answer.required}}" />
- </fieldset>
- <button type="button" ng-click="onValidate(); return false;"> Validate</button>
- <button type="submit"> Submit </button>
- </form>
- </my-form>
- var myApp=angular.module('CreateApp', []);
- myApp.controller('mainController', function($scope, $http) {
- $http.get('form.json').success(function(response) {
- $scope.result = response;
- console.log($scope.fields);
- });
- // function to submit the form after all validation has occurred
- $scope.submitForm = function() {
- // check to make sure the form is completely valid
- if ($scope.userForm.$valid) {
- alert('our form is amazing');
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement