2016-02-22 78 views
1

我想添加一個自定義類型到角度模式形式的UI引導datepicker。將自定義類型添加到角度模式形式 - datepicker

我按照說明操作,但打開表單時未顯示字段。

我的模塊,加載到頁面:

angular.module('schemaForm-datepicker', ['schemaForm']).config(
[ 
    'schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfPathProvider', 
    function (schemaFormProvider, schemaFormDecoratorsProvider, sfPathProvider) { 

     var picker = function (name, schema, options) { 
      console.log(schema.type); 
      if (schema.type === 'date') { 
       console.log("found"); 
       var f = schemaFormProvider.stdFormObj(name, schema, options); 
       f.key = options.path; 
       f.type = 'datepicker'; 
       options.lookup[sfPathProvider.stringify(options.path)] = f; 
       return f; 
      } 
     }; 

     schemaFormProvider.defaults.object.unshift(picker); 

     //Add to the bootstrap directive 
     schemaFormDecoratorsProvider.addMapping('bootstrapDecorator', 'datepicker', 
      'template/datepicker.html'); 
     schemaFormDecoratorsProvider.createDirective('datepicker', 
      'template/datepicker.html'); 
    } 
]); 

我的模板:

<div class="form-group" ng-class="{'has-error': hasError()}"> 
    <label class="control-label" ng-show="showTitle()">{{form.title}}</label> 

    <input type="text" 
      class="form-control" 
      schema-validate="form" 
      ng-model="$$value$$" 
      placeholder="Date" /> 

    <span class="help-block" sf-message="form.description"></span> 
</div> 

架構數據:

{"type":"object","properties":{"FirstName":{"type":"string","title":"FirstName"},"LastName":{"type":"string","title":"LastName"},"CompanyName":{"type":"string","title":"CompanyName"},"EmailAddress":{"type":"string","title":"EmailAddress"},"JoinDate":{"type":"date","title":"JoinDate"}}} 

任何想法?

回答

2

假設您正在進行更改日期類型。 您必須在模式中包含您的字段類型。 要實現添加上,你必須

  1. 添加一個新的類型的字段
  2. 添加一個新的裝飾

因爲它在文檔指出,新類型應該是addMapping第二個參數,然後提供模板並確保在模式中聲明該類型以顯示。

$scope.form = 
[ 
{ 
    key: "birthday", 
    type: "datepicker" 
} 
]; 

你的情況,你必須改變日期:

"JoinDate": {"type":"datepicker","title":"JoinDate"}. 

注:日期選擇器已經存在,你可以使用該表單類型。但只要您不包含角度模式形式的日期選擇器,您的自定義推進就可以工作文檔確實有一些信息,但第一次令人困惑。 https://github.com/json-schema-form/angular-schema-form/blob/master/docs/extending.md

對不起,我不能評論這麼張貼爲答案。

相關問題