- Notifications
You must be signed in to change notification settings - Fork 641
Open
Description
Is there a way to use a separate template for read-only fields?
My best effort was using default-rules (schemaFormProvider.defaults) to read my global formDefaults and then point to a custom type with a separate template (see example below), but then a type defined in the form-definition can still override that.
_(simplified example)_
In the below snippet:
- The schema-definition describes "a" as a string
- The default-rule sets "a" its type to read-only
- The form-definition appears to override "a" as a textarea
// schema-definition describes "a" as a string $scope.schema = { type: 'object', properties: { a: { type: 'string' } } } // default-rule sets "a" its type to read-only schemaFormProvider.defaults.string.unshift( function ( name, schema, options ) { if ( options.global.formDefaults.readonly ) { var f = schemaFormProvider.stdFormObj( name, schema, options ); f.key = options.path; f.type = 'read-only'; // refers to read_only.html template defined through schemaFormDecoratorsProvider.defineDecorator() options.lookup[ sfPathProvider.stringify( options.path )] = f; return f; } }); // form-definition appears to override default-rule ("a" becomes a textarea) $scope.form = [ { key: 'a', type: 'textarea' } // 'textarea' seems to override 'read-only' as set by my default-rule (below) ]Also interesting is that although it makes sense that defaults would only apply when no type is set, the default-rule is actually called on "a" (even though it already has a type) and the result of the default-rule is disregarded. Is this expected behavior?
I'm hoping the above describes the situation clearly enough – if not I can make a plunkr.