Skip to content

Commit 3de353e

Browse files
committed
Documentation and tests for help type
1 parent 63e939c commit 3de353e

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

docs/index.md

+38
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Documentation
1616
1. [actions](#actions)
1717
1. [button](#button)
1818
1. [radios and radiobuttons](#radios-and-radiobuttons)
19+
1. [help](#help)
1920
1. [Post process function](#post-process-function)
2021

2122
Form types
@@ -38,6 +39,7 @@ Schema Form currently supports the following form field types out of the box:
3839
| button | a button |
3940
| radios | radio buttons |
4041
| radiobuttons | radio buttons with bootstrap buttons |
42+
| help | insert arbitrary html |
4143

4244
More field types can be added, for instance a "datepicker" type can be added by
4345
including the [datepicker addon](datepicker.md)
@@ -364,6 +366,42 @@ function FormCtrl($scope) {
364366
}
365367
```
366368

369+
### help
370+
Help fields is not really a field, but instead let's you inser arbitrary HTML
371+
into a form, suitable for help texts with links etc.
372+
373+
It uses ```ng-bind-html``` so you need to include the
374+
[ngSanitize](https://docs.angularjs.org/api/ngSanitize) module for it to work,
375+
or expicitly turning of strict contextual escaping with
376+
```$sceProvider.enabled(false)``` (not recomended). It's enough to include
377+
```angular-sanitize.min.js``` before ```angular-schema.min.js``` and Schema Form
378+
will pick up that it's there and include it as a module dependency.
379+
380+
The get a help field you need to specify the type ```help``` and have a html
381+
snippet as a string in the option ```helpvalue```
382+
383+
Ex.
384+
```javascript
385+
function FormCtrl($scope) {
386+
$scope.schema = {
387+
type: "object",
388+
properties: {
389+
name: {
390+
title: "Name",
391+
type: "string"
392+
}
393+
}
394+
};
395+
396+
$scope.form = [
397+
{
398+
type: "help",
399+
helpvalue: "<h1>Yo Ninja!</h1>"
400+
},
401+
"name"
402+
];
403+
}
404+
```
367405

368406
Post process function
369407
---------------------

test/schema-form-test.js

+41
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,47 @@ describe('Schema form',function(){
851851
});
852852
});
853853

854+
it('should render custom html when type "help" is specified',function(){
855+
856+
//We don't need no sanitation. We don't need no though control.
857+
module(function($sceProvider){
858+
$sceProvider.enabled(false);
859+
});
860+
861+
inject(function($compile,$rootScope){
862+
var scope = $rootScope.$new();
863+
scope.person = { partee: '2014-01-01'};
864+
865+
scope.schema = {
866+
type: "object",
867+
properties: {
868+
name: {
869+
type: "string",
870+
}
871+
}
872+
};
873+
874+
875+
scope.form = [
876+
{
877+
type: "help",
878+
helpvalue: "<h1>Yo Ninja!</h1>"
879+
},
880+
"name"
881+
];
882+
883+
var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="person"></form>');
884+
885+
$compile(tmpl)(scope);
886+
$rootScope.$apply();
887+
888+
tmpl.children().length.should.eq(2);
889+
tmpl.children().eq(0).is('div').should.be.true;
890+
tmpl.children().eq(0).children().length.should.eq(1);
891+
tmpl.children().eq(0).children().html().should.be.eq("Yo Ninja!");
892+
893+
});
894+
});
854895

855896
});
856897

0 commit comments

Comments
 (0)