Permalink
Browse files

Add option to disable sorting on List editor

  • Loading branch information...
1 parent 3307573 commit 91285012e9785204d45b52c3f5b8d86fd5261c87 @powmedia committed Sep 15, 2011
Showing with 29 additions and 15 deletions.
  1. +6 −1 README.md
  2. +4 −2 src/backbone-forms.css
  3. +19 −12 src/jquery-ui-editors.js
View
@@ -215,7 +215,12 @@ Creates a sortable and editable list of items, which can be any of the above sch
- Optional, but recommended when using listType 'Object'
- A function that returns a string representing how the object should be displayed in a list item.
-- When listType is 'NestedModel', the model's `toString()` method will be used, unless a specific `itemToString()` function is defined on the schema.
+- When listType is 'NestedModel', the model's `toString()` method will be used, unless a specific `itemToString()` function is defined on the schema.
+
+**`sortable`**
+
+- Optional. Set to false to disable drag and drop sorting
+
Examples:
View
@@ -64,13 +64,15 @@
height: 16px;
background: #fff;
padding: 4px;
- cursor: move;
margin: 0;
list-style-type: none;
margin-top: -1px;
position: relative;
- }
+ }
+ .bbf-list-sortable li {
+ cursor: move;
+ }
.bbf-list .bbf-list-actions {
position: absolute;
View
@@ -174,17 +174,20 @@
},
render: function() {
+ var el = $(this.el);
+
//Main element
- $(this.el).html(this.template());
-
+ el.html(this.template());
+
//Create list
var self = this,
+ el = $(this.el),
data = this.value || [],
schema = this.schema,
itemToString = this.itemToString,
itemTemplate = this.itemTemplate,
- listEl = $('ul', this.el);
-
+ listEl = $('ul', el);
+
_.each(data, function(itemData) {
var text = itemToString.call(self, itemData);
@@ -198,22 +201,26 @@
});
//Make sortable
- listEl.sortable({
- axis: 'y',
- cursor: 'move',
- containment: 'parent'
- });
+ if (schema.sortable !== false) {
+ listEl.sortable({
+ axis: 'y',
+ cursor: 'move',
+ containment: 'parent'
+ });
+
+ el.addClass('bbf-list-sortable');
+ }
//jQuery UI buttonize
- $('button.bbf-list-add', this.el).button({
+ $('button.bbf-list-add', el).button({
text: false,
icons: { primary: 'ui-icon-plus' }
});
- $('button.bbf-list-edit', this.el).button({
+ $('button.bbf-list-edit', el).button({
text: false,
icons: { primary: 'ui-icon-pencil' }
});
- $('button.bbf-list-del', this.el).button({
+ $('button.bbf-list-del', el).button({
text: false,
icons: { primary: 'ui-icon-trash' }
});

0 comments on commit 9128501

Please sign in to comment.