@@ -190,11 +190,11 @@ var schema = {
190190 {
191191 key: " surname" ,
192192 type: " select" ,
193- titleMap: {
194- " Andersson" : " Andersson" ,
195- " Johansson" : " Johansson" ,
196- " other" : " Something else..."
197- }
193+ titleMap: [
194+ { value : " Andersson" , name : " Andersson" } ,
195+ { value : " Johansson" , name : " Johansson" } ,
196+ { value : " other" , name : " Something else..." }
197+ ]
198198 }
199199]
200200```
@@ -361,10 +361,28 @@ scope.
361361
362362### select and checkboxes
363363
364- * select* and * checkboxes* can take an object, ``` titleMap ``` , where key is the value to be saved on the model
365- and the value is the title of the option. In the case of * checkboxes* the values
366- of the titleMap can be HTML.
364+ * select* and * checkboxes* can take an attribute, ` titleMap ` , wich defines a name
365+ and a value. The value is bound to the model while the name is used for display.
366+ In the case of * checkboxes* the names of the titleMap can be HTML.
367+
368+ A ` titleMap ` can be specified as either an object (same as in JSON Form), where
369+ the propery is the value and the value of that property is the name, or as
370+ a list of name-value objects. The latter is used internally and is the recomended
371+ format to use. Note that when defining a ` titleMap ` as an object the value is
372+ restricted to strings since property names of objects always is a string.
373+
374+ As a list:
375+ ``` javascript
376+ {
377+ type: " select" ,
378+ titleMap: [
379+ { value: " yes" , name: " Yes I do" },
380+ { value: " no" , name: " Hell no" }
381+ ]
382+ }
383+ ```
367384
385+ As an object:
368386``` javascript
369387{
370388 type: " select" ,
@@ -423,9 +441,12 @@ We can change this with ```style``` attribute:
423441```
424442
425443### radios and radiobuttons
426- Both type * radios* and * radiobuttons* work the same way, they take a titleMap
427- and renders ordinary radio buttons or bootstrap 3 buttons inline. It's a
428- cosmetic choice. The value in the titleMap can be HTML.
444+ Both type * radios* and * radiobuttons* work the same way.
445+ They take a ` titleMap ` and renders ordinary radio buttons or bootstrap 3 buttons
446+ inline. It's a cosmetic choice.
447+
448+ The ` titleMap ` is either a list or an object, see [ select and checkboxes] ( #select-and-checkboxes )
449+ for details. The "name" part in the ` titleMap ` can be HTML.
429450
430451Ex.
431452``` javascript
@@ -444,15 +465,45 @@ function FormCtrl($scope) {
444465 {
445466 key: " choice" ,
446467 type: " radiobuttons" ,
447- titleMap: {
448- one: " One" ,
449- two: " More..."
468+ titleMap: [
469+ { value: " one" , name: " One" },
470+ { value, " two" , name: " More..." }
471+ ]
472+ }
473+ ];
474+ }
475+ ```
476+
477+ The actual schema property it binds doesn't need to be a string with an enum.
478+ Here is an example creating a yes no radio buttons that binds to a boolean.
479+
480+ Ex.
481+ ``` javascript
482+ function FormCtrl ($scope ) {
483+ $scope .schema = {
484+ type: " object" ,
485+ properties: {
486+ confirm: {
487+ type: " boolean" ,
488+ default: false
450489 }
451490 }
491+ };
492+
493+ $scope .form = [
494+ {
495+ key: " choice" ,
496+ type: " radios" ,
497+ titleMap: [
498+ { value: false , name: " No I don't understand these cryptic terms" },
499+ { value: true , , name: " Yes this makes perfect sense to me" }
500+ ]
501+ }
452502 ];
453503}
454504```
455505
506+
456507With * radiobuttons* , both selected and unselected buttons have btn-primary as default.
457508We can change this with ``` style ``` attribute:
458509``` javascript
@@ -475,11 +526,10 @@ function FormCtrl($scope) {
475526 selected: " btn-success" ,
476527 unselected: " btn-default"
477528 },
478- titleMap: {
479- one: " One" ,
480- two: " More..."
481- }
482- }
529+ titleMap: [
530+ { value: " one" , name: " One" },
531+ { value, " two" , name: " More..." }
532+ ]
483533 ];
484534}
485535` ` `
@@ -515,9 +565,9 @@ function FormCtrl($scope) {
515565` ` `
516566
517567### tabs
518- The ``` tabs `` ` form type lets you split your form into tabs. It is similar to
519- ``` fieldset ``` in that it just changes the presentation of the form. ``` tabs `` `
520- takes a option, also called ``` tabs `` ` , that is a list of tab objects. Each tab
568+ The ` tabs` form type lets you split your form into tabs. It is similar to
569+ ` fieldset` in that it just changes the presentation of the form. ` tabs`
570+ takes a option, also called ` tabs` , that is a list of tab objects. Each tab
521571object consist of a *title* and a *items* list of form objects.
522572
523573Ex.
@@ -570,17 +620,17 @@ function FormCtrl($scope) {
570620` ` `
571621
572622### array
573- The ``` array ``` form type is the default for the schema type ``` array `` ` .
574- The schema for an array has the property ``` "items" `` ` which in the JSON Schema
623+ The ` array` form type is the default for the schema type ` array` .
624+ The schema for an array has the property ` " items" ` which in the JSON Schema
575625specification can be either another schema (i.e. and object), or a list of
576626schemas. Only a schema is supported by Schema Form, and not the list of schemas.
577627
578- The * form* definition has the option ``` ìtems `` ` that should be a list
628+ The *form* definition has the option ` items ` that should be a list
579629of form objects.
580630
581631The rendered list of subforms each have a *"Remove"* button and at the bottom there
582632is an *"Add"* button. The default *"Add"* button has class btn-default and text Add. Both
583- could be changed using attribute ``` add `` ` , see example below.
633+ could be changed using attribute ` add` , see example below.
584634
585635If you like to have drag and drop reordering of arrays you also need
586636[ui-sortable](https://github.com/angular-ui/ui-sortable) and its dependencies
@@ -589,7 +639,7 @@ what parts of jQueryUI that is needed. You can safely ignore these if you don't
589639need the reordering.
590640
591641In the form definition you can refer to properties of an array item by the empty
592- bracket notation. In the ``` key ``` simply end the name of the array with ``` [] `` `
642+ bracket notation. In the ` key` simply end the name of the array with ` [] `
593643
594644Given the schema:
595645` ` ` json
@@ -615,8 +665,8 @@ Given the schema:
615665 }
616666}
617667` ` `
618- Then ``` subforms[].name `` ` refers to the property name of any subform item,
619- ``` subforms[].emails[] `` ` refers to the subform of emails. See example below for
668+ Then ` subforms[].name ` refers to the property name of any subform item,
669+ ` subforms[].emails []` refers to the subform of emails. See example below for
620670usage.
621671
622672
@@ -642,7 +692,7 @@ function FormCtrl($scope) {
642692
643693
644694Example with sub form, note that you can get rid of the form field the object wrapping the
645- subform fields gives you per default by using the ``` items `` ` option in the
695+ subform fields gives you per default by using the ` items` option in the
646696form definition.
647697
648698` ` ` javascript
@@ -689,24 +739,24 @@ function FormCtrl($scope) {
689739
690740
691741### tabarray
692- The ``` tabarray `` ` form type behaves the same way and has the same options as
693- ``` array `` ` but instead of rendering a list it renders a tab per item in list.
742+ The ` tabarray` form type behaves the same way and has the same options as
743+ ` array` but instead of rendering a list it renders a tab per item in list.
694744
695745By default the tabs are on the left side (follows the default in JSON Form),
696- but with the option ``` tabType `` ` you can change that to eiter * "top"* or * "right"*
746+ but with the option ` tabType` you can change that to eiter *"top"* or *"right"*
697747as well.
698748
699749Every tab page has a *"Remove"* button. The default *"Remove"* button has class btn-default
700- and text Remove. Both could be changed using attribute ``` remove `` ` , see example below.
750+ and text Remove. Both could be changed using attribute ` remove` , see example below.
701751
702- In this case we have an * "Add"* link, not an * "Add"* button. Therefore, the attribute ``` add `` `
752+ In this case we have an *"Add"* link, not an *"Add"* button. Therefore, the attribute ` add`
703753only changes the text of the link. See example below.
704754
705755Bootstrap 3 doesn't have side tabs so to get proper styling you need to add the
706756dependency [bootstrap-vertical-tabs](https://github.com/dbtek/bootstrap-vertical-tabs).
707757It is not needed for tabs on top.
708758
709- The ``` title ``` option is a bit special in ``` tabarray `` ` , it defines the title
759+ The ` title` option is a bit special in ` tabarray` , it defines the title
710760of the tab and is considered a angular expression. The expression is evaluated
711761with two extra variables in context: **value** and **$index**, where **value**
712762is the value in the array (i.e. that tab) and **$index** the index.
@@ -766,9 +816,9 @@ function FormCtrl($scope) {
766816Post process function
767817---------------------
768818
769- If you like to use ``` ["*"] `` ` as a form, or aren't in control of the form definitions
819+ If you like to use ` [" *" ]` as a form, or aren't in control of the form definitions
770820but really need to change or add something you can register a *post process*
771- function with the ``` schemaForm `` ` service provider. The post process function
821+ function with the ` schemaForm` service provider. The post process function
772822gets one argument, the final form merged with the defaults from the schema just
773823before it's rendered, and should return a form.
774824
0 commit comments