Skip to content

override input templates #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iivvoo opened this issue Aug 8, 2014 · 9 comments
Closed

override input templates #57

iivvoo opened this issue Aug 8, 2014 · 9 comments

Comments

@iivvoo
Copy link

iivvoo commented Aug 8, 2014

I (think I) need to override the individual (html) field definitions. I want to render my form horizontally (class=form-horizontal) but I understand this requires the input control to be wrapped in a div with a specific grid sizing class (e.g. col-md-8)

What options are there (besides forking :) to override the fields templates?

@mike-marcacci
Copy link
Contributor

Hi @iivvoo, I believe you can use the schemaFormProvider to add/override form directives/decorators. I'm not 100% sure what that looks like right now, but I'm going to be looking into it (I'm working to add a ckeditor field type today).

I do know you can also duplicate the entire decorators/bootstrap directory and add the attribute sf-decorator="your-decorator-name" to the form element (that attribute is going to change to sf-decorator-name very soon though per #49).

Hope that helps a bit!

@davidlgj
Copy link
Contributor

Hi @iivvoo

as @mike-marcacci stated above you can basically copy the decorators/bootstrap folder, edit bootstrap-decorator.js and rename it. You probably also want to edit the gulp file so it builds a version for your new decorator as well.

Setting sf-decorator="your-decorator-name" on the same element as the sf-schema is supposed to work but does have a couple of bugs right now. But if your decorator is the only one included (i.e. don't include bootstrap-decorator.min.js) then it's used by default, and that should work.

@iivvoo
Copy link
Author

iivvoo commented Aug 11, 2014

Thanks @mike-marcacci and @davidlgj
I think I understand the decorator solution (and implications), I don't really know what to do with the schemaFormProvider suggestion.

But if I understand correctly, the decorator solution does mean I need to fork / build my own bootstrap-decorator.js? Wouldn't a more generic solution be more flexible? (I'm not sure how easy it is to just rip out the decorator stuff)

I can imagine other cases where you may want to render fields differently from the default (but the form-horizontal is a very obvious one of course).

My client might be willing to sponsor such a feature..

@mike-marcacci
Copy link
Contributor

Hi @iivvoo, it turns out that it is quite easy to override a single template (or add new ones). For example:

1 - Create your template

<div class="form-group has-feedback" ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}">
    <label ng-show="showTitle()">{{form.title}}</label>
    <span class="help-block">{{ (hasError() && errorMessage(schemaError())) || form.description}}</span>
    <textarea class="form-control"
                        ckeditor
                        sf-changed="form"
                        ng-required="form.required"
                        ng-model="$$value$$"
                        schema-validate="form.schema"></textarea>
</div>

2 - Use the addMapping provider method:

.config(['schemaFormDecoratorsProvider', function(decoratorsProvider){
    decoratorsProvider.addMapping('bootstrapDecorator', 'ckeditor', 'path/to/ckeditor.html');
}])

@iivvoo
Copy link
Author

iivvoo commented Aug 21, 2014

This is exactly the type of solution I was looking for. It works perfectly, thanks!

@mike-marcacci
Copy link
Contributor

Glad to help!

@davidlgj
Copy link
Contributor

@111crb111
Copy link

Hi, i'm angularjs noob :) wher i need write this

 .config(['schemaFormDecoratorsProvider', function(decoratorsProvider){
    decoratorsProvider.addMapping('bootstrapDecorator', 'ckeditor', 'path/to/ckeditor.html');
}])

i think need some file like extendForm.js but dont know how use that function :(
may you please post full example?

cteiosanu added a commit to cteiosanu/angular-schema-form that referenced this issue May 12, 2015
I've copied the explanation of @mike-marcacci from ticket json-schema-form#57 and add as an example in the Decorators section.
@aman-gautam
Copy link

@mike-marcacci Do we need to put the custom template in $templateCache? Is there a step by step example on how to override the input templates?

Thanks,
Aman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants