@@ -61,6 +61,7 @@ Schema Form currently supports the following form field types:
6161|:--------------|:------------------------|
6262| fieldset | a fieldset with legend |
6363| section | just a div |
64+ | conditional | a section with a ` ` ` ng- if ` ` ` |
6465| actions | horizontal button list, can only submit and buttons as items |
6566| text | input with type text |
6667| textarea | a textarea |
@@ -214,6 +215,56 @@ They do need a list of ```items``` to have as children.
214215}
215216` ` `
216217
218+ A *conditional* is exactly the same as a *section*, i.e. a ` ` ` < div> ` ` ` with other form elements in
219+ it, hence they *section* needs an ` ` ` items` ` ` property. They also need a ` ` ` condition` ` ` which is
220+ a string with an angular expression. If that expression evaluates as thruthy the *conditional*
221+ will be rendered into the DOM otherwise not. The expression is evaluated in the parent scope of
222+ the ` ` ` sf- schema` ` ` directive (the same as onClick on buttons). This is useful for hiding/showing
223+ parts of a form depending on another form control.
224+
225+ ex. A checkbox that shows an input field for a code when checked
226+
227+ ` ` ` javascript
228+ function FormCtrl ($scope ) {
229+ $scope .person = {}
230+
231+ $scope .schema = {
232+ " type" : " object" ,
233+ " properties" : {
234+ " name" : {
235+ " type" : " string" ,
236+ " title" : " Name"
237+ },
238+ " eligible" : {
239+ " type" : " boolean" ,
240+ " title" : " Eligible for awesome things"
241+ },
242+ " code" : {
243+ " type" : " string"
244+ " title" : " The Code"
245+ }
246+ }
247+ }
248+
249+ $scope .form = [
250+ " name" ,
251+ " eligible" ,
252+ {
253+ type: " conditional" ,
254+ condition: " person.eligible" ,
255+ items: [
256+ " code"
257+ ]
258+ }
259+ ]
260+ }
261+ ` ` `
262+ Note that angulars two-way binding automatically will update the conditional block, no need for
263+ event handlers and such. The condition need not reference a model value it could be anything in
264+ scope.
265+
266+
267+
217268
218269*select* and *checkboxes* can take an object, ` ` ` titleMap` ` ` , where key is the value to be saved on the model
219270and the value is the title of the option.
0 commit comments