angular-schema-form

How to always validate an angular json schema form?


I am using angular-schema-form, and ran into a problem that when I load a schema and a form from a server using REST, the validation sometimes did not kick in. I could post a schema even though some fields were required.

How can I always be sure that the required fields in the form has to be filled in by the user before posting?


Solution

  • I found that using $scope.$broadcast('schemaFormValidate'); before submitting the form works (from the docs).

    $scope.onSubmit = function(form) {
        // First we broadcast an event so all fields validate themselves
        $scope.$broadcast('schemaFormValidate');
    
        // Then we check if the form is valid
        if (form.$valid) {
          // ... do whatever you need to do with your data.
        }
      }
    

    However, we can not disable any buttons beforehand.