我正在尝试使用新的构建器编写插件。到目前为止一切顺利,但我没有让它听 schema.format。
这是一个使用 ui-bootstrap 的简单日期选择器。
angular.module('angularSchemaFormUiDatepicker', [
'ui.bootstrap',
'schemaForm',
'templates',
'pascalprecht.translate'
]).config(function(schemaFormProvider, schemaFormDecoratorsProvider, sfBuilderProvider, sfPathProvider) {
var addOn = schemaFormDecoratorsProvider.defineAddOn(
'bootstrapDecorator', // Name of the decorator you want to add to.
'datepicker', // Form type that should render this add-on
'src/templates/angular-schema-form-ui-datepicker.html', // Template name in $templateCache
sfBuilderProvider.stdBuilders // List of builder functions to apply.
);
schemaFormProvider.prependRule('string', function(name, schema, options) {
if (schema.format === 'datepicker') {
// dirty workaround here
if (schema['x-schema-form']) {
schema['x-schema-form'].type = 'datepicker';
} else {
schema['x-schema-form'] = {
type: 'datepicker'
}
}
var f = schemaFormProvider.stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'datepicker';
options.lookup[sfPathProvider.stringify(options.path)] = f;
return f;
}
});
});