angular-schema-form icon indicating copy to clipboard operation
angular-schema-form copied to clipboard

Is it possible to support inline templates rather than template url for decorators?

Open romiem opened this issue 10 years ago • 4 comments

The angular convention when specifying templates in directives/components is to use the template property when supplying inline HTML, and templateUrl when specifying a url.

Schema-form seems to only have the 'template' property, but confusingly, it actually means templateUrl in schema-form world.

I understand that you probably don't want to change the API now, but is there any way of specifying inline HTML, maybe by creating a templateHtml property when defining the decorator?

At the moment you have this:

decoratorsProvider.defineDecorator('myDecorator', { 
    textarea: {template: base + 'textarea.html', builder: defaults}
}, []); 

I would like to do this:

decoratorsProvider.defineDecorator('myDecorator', { 
    textarea: {templateHtml: '<div class="my-decorator"></div>', builder: defaults}
}, []); 

romiem avatar Feb 12 '16 10:02 romiem

+1. This would be particularly useful when running a webpack build.

Choc13 avatar Feb 12 '16 10:02 Choc13

+1 would make life a little easier!

baileydoestech avatar Feb 15 '16 15:02 baileydoestech

The new alphas are built with webpack using the following format:

import actionsTemplate from './bootstrap/actions.html';

var defaults = [sfField, ngModel, ngModelOptions, condition];
decoratorsProvider.defineDecorator('bootstrapDecorator', {
  actions: {template: actionsTemplate, builder: defaults},

Combined with 'ngtemplate-loader' it imports everything during the build and adds them to cache.

Alternatively if you look at the calculate add-on in the example folder you will see how to add the template cache into your add-on


  .run(function($templateCache) {
    // A template to use
    $templateCache.put('calculated-fields.html','<calculate sf-field-model model="model" form="form" />');
  })
  .config([ 'schemaFormDecoratorsProvider', 'sfBuilderProvider',
    function(schemaFormDecoratorsProvider, sfBuilderProvider) {
      var sfField             = sfBuilderProvider.builders.sfField;
      var ngModel             = sfBuilderProvider.builders.ngModel;
      var defaults = [ sfField, ngModel ];

      schemaFormDecoratorsProvider.defineAddOn(
        'bootstrapDecorator',
        'calculate',
        'calculated-fields.html',
        defaults
      );
    }
  ]);

Anthropic avatar Apr 20 '17 13:04 Anthropic

Please re-open if you do not feel the question has been answered sufficiently.

Anthropic avatar Apr 20 '17 13:04 Anthropic