Skip to content

Commit

Permalink
Merge pull request kevinchappell#120 from kevinchappell/chore/updateDocs
Browse files Browse the repository at this point in the history
Update documentation, remove fieldOrder from sessionStorage when option disabled
  • Loading branch information
kevinchappell committed Mar 30, 2016
2 parents 442ba59 + fdb8738 commit f66aa71
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 8 deletions.
10 changes: 9 additions & 1 deletion demo/assets/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,15 @@ function formBuilderHelpersFn(opts, formBuilder) {
* @return {Array}
*/
_helpers.orderFields = function (frmbFields) {
var fieldOrder = window.sessionStorage ? window.sessionStorage.getItem('fieldOrder') : false;
var fieldOrder = false;

if (window.sessionStorage) {
if (opts.sortableControls) {
fieldOrder = window.sessionStorage.getItem('fieldOrder');
} else {
window.sessionStorage.removeItem('fieldOrder');
}
}

if (!fieldOrder) {
fieldOrder = opts.controlOrder.unique();
Expand Down
4 changes: 2 additions & 2 deletions demo/assets/js/form-builder.min.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion dist/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,15 @@ function formBuilderHelpersFn(opts, formBuilder) {
* @return {Array}
*/
_helpers.orderFields = function (frmbFields) {
var fieldOrder = window.sessionStorage ? window.sessionStorage.getItem('fieldOrder') : false;
var fieldOrder = false;

if (window.sessionStorage) {
if (opts.sortableControls) {
fieldOrder = window.sessionStorage.getItem('fieldOrder');
} else {
window.sessionStorage.removeItem('fieldOrder');
}
}

if (!fieldOrder) {
fieldOrder = opts.controlOrder.unique();
Expand Down
4 changes: 2 additions & 2 deletions dist/form-builder.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ Nearly every site and app will use formBuilder in a different way and to accommo
<pre><code class="js">
var defaults = {
controlPosition: 'right',
controlOrder: [
'autocomplete',
'button',
'checkbox',
'checkbox-group',
'date',
'file',
'header',
'hidden',
'paragraph',
'radio-group',
'select',
'text',
'textarea'
],
dataType: 'xml',
disableFields: ['autocomplete', 'hidden'],
append: false,
Expand Down
15 changes: 15 additions & 0 deletions docs/options/appendPrepend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# append, prepend
`append` and `prepend` allows you to define a block of arbitrary html to appear in the editor. This html is not editable and serves to provide a more accurate representation of what their form will look like in relation to items they cannot edit.

## Usage
```javascript
var options = {
prepend: '<h1>Profile for Miss Marple.</h1>',
append: '<h2>All information is confidential.</h2>'
};
$(template).formBuilder(options);
```


## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="XXYdvv" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/XXYdvv">formBuilder: append, prepend</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
17 changes: 17 additions & 0 deletions docs/options/controlOrder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# controlOrder
`controlOrder` allows you to define a new order for the elements in the control bar.

## Usage
```javascript
var options = {
controlOrder: [
'text',
'textarea'
]
};
$(template).formBuilder(options);
```


## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="rezdaa" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/rezdaa">formBuilder: controlOrder</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
14 changes: 14 additions & 0 deletions docs/options/controlPosition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# controlPosition
`controlPosition` allows you to set the elements to be dropped on the stage to either the left or right side.

## Usage
```javascript
var options = {
controlPosition: 'left'
};
$(template).formBuilder(options);
```


## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="bpRBVL" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/bpRBVL">formBuilder: controlPosition</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
2 changes: 1 addition & 1 deletion docs/options/disableFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ $(template).formBuilder(options);


## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="NNdbVx" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/NNdbVx/">formBuilder: disableFields</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
<p data-height="494" data-theme-id="22927" data-slug-hash="NNdbVx" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/NNdbVx">formBuilder: disableFields</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
14 changes: 14 additions & 0 deletions docs/options/fieldRemoveWarn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# fieldRemoveWarn
`fieldRemoveWarn` warn user's if before the remove a field from the stage.

## Usage
```javascript
var options = {
fieldRemoveWarn: true // defaults to false
};
$(template).formBuilder(options);
```


## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="aNyGdq" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/aNyGdq">formBuilder: fieldRemoveWarn</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
17 changes: 17 additions & 0 deletions docs/options/messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# messages
`messages` Pass a language object as an option to make formBuilder translatable.

## Usage
```javascript
var options = {
messages: {
select: 'Fabulous Dropdown'
}
};
$(template).formBuilder(options);
```

## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="BjxNKZ" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/BjxNKZ">formBuilder: messages</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>

For a more advanced example see: [Demos->Translation](/demos/translation/)
23 changes: 23 additions & 0 deletions docs/options/notify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# notify
`notify` Use your existing notifications.

## Usage
```javascript
var options = {
notify: {
error: function(message) {
return console.error(message);
},
success: function(message) {
return console.log(message);
},
warning: function(message) {
return console.warn(message);
}
}
};
$(template).formBuilder(options);
```

## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="xVrOVr" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/xVrOVr">formBuilder: notify</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
13 changes: 13 additions & 0 deletions docs/options/sortableControls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# sortableControls
`sortableControls` Allows user's to reorder the controls to their liking. Positions are saved to `window.sessionStorage`.

## Usage
```javascript
var options = {
sortableControls: true // defaults to false
};
$(template).formBuilder(options);
```

## See it in Action
<p data-height="494" data-theme-id="22927" data-slug-hash="eZErvG" data-default-tab="result" data-user="kevinchappell" class="codepen">See the Pen <a href="http://codepen.io/kevinchappell/pen/eZErvG">formBuilder: sortableControls</a> by Kevin Chappell (<a href="http://codepen.io/kevinchappell">@kevinchappell</a>) on <a href="http://codepen.io">CodePen</a>.</p>
7 changes: 7 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ pages:
- Translating: demos/translation.md
- Options:
- Overview: options.md
- append/prepend: options/appendPrepend.md
- controlPosition: options/controlPosition.md
- controlOrder: options/controlOrder.md
- disableFields: options/disableFields.md
- fieldRemoveWarn: options/fieldRemoveWarn.md
- messages: options/messages.md
- notify: options/notify.md
- sortableControls: options/sortableControls.md
- Contributing: contributing.md
- About:
- License: license.md
Expand Down
10 changes: 9 additions & 1 deletion src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,15 @@ function formBuilderHelpersFn(opts, formBuilder) {
* @return {Array}
*/
_helpers.orderFields = function(frmbFields) {
var fieldOrder = window.sessionStorage ? window.sessionStorage.getItem('fieldOrder') : false;
var fieldOrder = false;

if (window.sessionStorage) {
if (opts.sortableControls) {
fieldOrder = window.sessionStorage.getItem('fieldOrder');
} else {
window.sessionStorage.removeItem('fieldOrder');
}
}

if (!fieldOrder) {
fieldOrder = opts.controlOrder.unique();
Expand Down

0 comments on commit f66aa71

Please sign in to comment.