Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Sticky" fields #136

Open
wants to merge 4 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions dist/formbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
var attrs;
attrs = _.clone(this.model.attributes);
delete attrs['id'];
delete attrs['sticky'];
attrs['label'] += ' Copy';
return this.parentView.createField(attrs, {
position: this.model.indexInDOM() + 1
Expand Down Expand Up @@ -197,6 +198,9 @@
rivets.bind(this.$el, {
model: this.model
});
if (this.model.attributes.sticky) {
this.$el.find('.fb-label-description').find('input').filter('[type=text]').attr('readonly', 'readonly');
}
return this;
};

Expand Down Expand Up @@ -587,7 +591,8 @@
MAX: 'field_options.max',
MINLENGTH: 'field_options.minlength',
MAXLENGTH: 'field_options.maxlength',
LENGTH_UNITS: 'field_options.min_max_length_units'
LENGTH_UNITS: 'field_options.min_max_length_units',
STICKY: 'sticky'
},
dict: {
ALL_CHANGES_SAVED: 'All changes saved',
Expand Down Expand Up @@ -1146,13 +1151,18 @@ return __p

this["Formbuilder"]["templates"]["view/duplicate_remove"] = function(obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape;
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
with (obj) {
__p += '<div class=\'actions-wrapper\'>\n <a class="js-duplicate ' +
((__t = ( Formbuilder.options.BUTTON_CLASS )) == null ? '' : __t) +
'" title="Duplicate Field"><i class=\'fa fa-plus-circle\'></i></a>\n <a class="js-clear ' +
'" title="Duplicate Field"><i class=\'fa fa-plus-circle\'></i></a>\n ';
if(!rf.get(Formbuilder.options.mappings.STICKY)) { ;
__p += '\n <a class="js-clear ' +
((__t = ( Formbuilder.options.BUTTON_CLASS )) == null ? '' : __t) +
'" title="Remove Field"><i class=\'fa fa-minus-circle\'></i></a>\n</div>';
'" title="Remove Field"><i class=\'fa fa-minus-circle\'></i></a>\n ';
} ;
__p += '\n</div>';

}
return __p
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ViewFieldView extends Backbone.View
duplicate: ->
attrs = _.clone(@model.attributes)
delete attrs['id']
delete attrs['sticky']
attrs['label'] += ' Copy'
@parentView.createField attrs, { position: @model.indexInDOM() + 1 }

Expand All @@ -84,6 +85,8 @@ class EditFieldView extends Backbone.View
render: ->
@$el.html(Formbuilder.templates["edit/base#{if !@model.is_input() then '_non_input' else ''}"]({rf: @model}))
rivets.bind @$el, { model: @model }
if @model.attributes.sticky
@$el.find('.fb-label-description').find('input').filter('[type=text]').attr('readonly', 'readonly')
return @

remove: ->
Expand Down Expand Up @@ -391,6 +394,7 @@ class Formbuilder
MINLENGTH: 'field_options.minlength'
MAXLENGTH: 'field_options.maxlength'
LENGTH_UNITS: 'field_options.min_max_length_units'
STICKY: 'sticky'

dict:
ALL_CHANGES_SAVED: 'All changes saved'
Expand Down
2 changes: 2 additions & 0 deletions src/templates/view/duplicate_remove.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class='actions-wrapper'>
<a class="js-duplicate <%= Formbuilder.options.BUTTON_CLASS %>" title="Duplicate Field"><i class='fa fa-plus-circle'></i></a>
<% if(!rf.get(Formbuilder.options.mappings.STICKY)) { %>
<a class="js-clear <%= Formbuilder.options.BUTTON_CLASS %>" title="Remove Field"><i class='fa fa-minus-circle'></i></a>
<% } %>
</div>
Loading