@@ -4,6 +4,7 @@ Documentation
4
4
1 . [ Basic Usage] ( #basic-usage )
5
5
1 . [ Handling Submit] ( #handling-submit )
6
6
1 . [ Global Options] ( #global-options )
7
+ 1 . [ Form defaults in schema] ( #form-defaults-in-schema )
7
8
1 . [ Form types] ( #form-types )
8
9
1 . [ Default form types] ( #default-form-types )
9
10
1 . [ Form definitions] ( #form-definitions )
@@ -25,6 +26,7 @@ Documentation
25
26
1 . [ array] ( #array )
26
27
1 . [ tabarray] ( #tabarray )
27
28
1 . [ Post process function] ( #post-process-function )
29
+ 1 . [ Events] ( #events )
28
30
1 . [ Manual field insertion] ( #manual-field-insertion )
29
31
1 . [ Extending Schema Form] ( extending.md )
30
32
173
175
< / div>
174
176
` ` `
175
177
178
+ Form defaults in schema
179
+ -----------------------
180
+ Its recommended to split presentation and validation into a form definition and a json schema. But
181
+ if you for some reason can't do this, but *do* have the power to change the schema, you can supply form
182
+ default values within the schema using the custom attribute ` x- schema- form` . ` x- schema- form` should
183
+ be a form object and acts as form definition defaults for that field.
176
184
185
+ Example schema.
186
+ ` ` ` js
187
+ {
188
+ " type" : " object" ,
189
+ " properties" : {
190
+ " comment" : {
191
+ " type" : " string" ,
192
+ " title" : " Comment" ,
193
+ " x-schema-form" : {
194
+ " type" : " textarea" ,
195
+ " placeholder" : " Don't hold back"
196
+ }
197
+ }
198
+ }
199
+ }
200
+ ` ` `
177
201
178
202
Form types
179
203
----------
@@ -314,8 +338,10 @@ General options most field types can handle:
314
338
feedback: false , // Inline feedback icons
315
339
placeholder: " Input..." , // placeholder on inputs and textarea
316
340
ngModelOptions: { ... }, // Passed along to ng-model-options
317
- readonly: true // Same effect as readOnly in schema. Put on a fieldset or array
341
+ readonly: true , // Same effect as readOnly in schema. Put on a fieldset or array
318
342
// and their items will inherit it.
343
+ htmlClass: " street foobar" , // CSS Class(es) to be added to the container div
344
+ fieldHtmlClass: " street" // CSS Class(es) to be added to field input (or similar)
319
345
}
320
346
` ` `
321
347
@@ -836,6 +862,9 @@ need the reordering.
836
862
In the form definition you can refer to properties of an array item by the empty
837
863
bracket notation. In the ` key` simply end the name of the array with ` []`
838
864
865
+ By default the array will start with one *undefined* value so that the user is presented with one a
866
+ form, to supress this the attribute ` startEmpty` to ` true `
867
+
839
868
Given the schema:
840
869
` ` ` json
841
870
{
@@ -888,7 +917,7 @@ function FormCtrl($scope) {
888
917
889
918
Example with sub form, note that you can get rid of the form field the object wrapping the
890
919
subform fields gives you per default by using the ` items` option in the
891
- form definition.
920
+ form definition, also example of ` startEmpty ` .
892
921
893
922
` ` ` javascript
894
923
function FormCtrl ($scope ) {
@@ -926,7 +955,8 @@ function FormCtrl($scope) {
926
955
" subforms[].nick" ,
927
956
" subforms[].name" ,
928
957
" subforms[].emails" ,
929
- ]
958
+ ],
959
+ startEmpty: true
930
960
}
931
961
];
932
962
}
@@ -1029,7 +1059,14 @@ angular.module('myModule', ['schemaForm']).config(function(schemaFormProvider){
1029
1059
});
1030
1060
` ` `
1031
1061
1062
+ Events
1063
+ ---------------------
1064
+ Events are emitted or broadcast at various points in the process of rendering or validating the
1065
+ form. Below is a list of these events and how they are propagated.
1032
1066
1067
+ | Event | When | Type | Arguments |
1068
+ |:--------------------:|:----------------------:|:-----:|:----------------------------------:|
1069
+ | ` sf- render- finished` | After form is rendered | emit | The sf-schema directives's element |
1033
1070
1034
1071
### Manual field insertion
1035
1072
There is a limited feature for controlling manually where a generated field should go so you can
0 commit comments