Search code examples
javascriptangularjsangular-schema-form

Angular Schema Form - Custom Field


I'm trying to add new form fields to angular schema form directive. The documentation (https://github.com/Textalk/angular-schema-form/blob/master/docs/extending.md) says to use a function call like below to do that,

 schemaFormDecoratorsProvider.addMapping(
  'bootstrapDecorator',
  'datepicker',
  'directives/decorators/bootstrap/datepicker/datepicker.html'
);

I'm new to angularjs and I'm not sure from where to call this function. I've tried different methods and nothing made it work. Can someone provide a jsfiddle to show how to do this, or give me some hints..

Thanks in advance.


Solution

  • As the link in the example states ("Ex. from the datepicker add-on"), you need to add a following config() block:

    angular.module('schemaForm').config(
    ['schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfPathProvider',
      function(schemaFormProvider,  schemaFormDecoratorsProvider, sfPathProvider) {
    
        // Use schemaFormProvider,  schemaFormDecoratorsProvider, sfPathProvider here
        // to configure the custom field
      }
    ]);
    

    It can be just added on the top level of your app code, like this:

    angular.module('schemaForm').config(...)
    
    var app = angular.module("test", ["schemaForm"]);
    
    app.controller("FormController", function ($scope) {
        $scope.schema = { ... }
        ...
    });
    

    Update: here is a jsfiddle demonstrating this.