-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Copy Button Added #252
Copy Button Added #252
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,8 @@ | |
close: 'Close', | ||
content: 'Content', | ||
copy: 'Copy To Clipboard', | ||
copyButton: '+', | ||
copyButtonTooltip: 'Copy', | ||
dateField: 'Date Field', | ||
description: 'Help Text', | ||
descriptionField: 'Description', | ||
|
@@ -927,10 +929,15 @@ | |
id: lastID + '-edit', | ||
className: 'toggle-form btn icon-pencil', | ||
title: opts.messages.hide | ||
}), | ||
copyBtn = utils.markup('a', opts.messages.copyButton, { | ||
id: lastID + '-copy', | ||
className: 'copy-button btn icon-copy', | ||
title: opts.messages.copyButtonTooltip | ||
}); | ||
|
||
var liContents = utils.markup( | ||
'div', [toggleBtn, delBtn], { className: 'field-actions' } | ||
'div', [toggleBtn, copyBtn, delBtn], { className: 'field-actions' } | ||
).outerHTML; | ||
|
||
// Field preview Label | ||
|
@@ -1024,6 +1031,45 @@ | |
let field = utils.markup('li', optionInputs); | ||
|
||
return field.outerHTML; | ||
}; | ||
|
||
var cloneItem = function cloneItem(currentItem) { | ||
var currentId = currentItem.attr("id"); | ||
var cloneName = currentItem.attr("type"); | ||
var ts = new Date().getTime(); | ||
cloneName = cloneName + "-" + ts; | ||
|
||
var $clone = currentItem.clone(); | ||
|
||
$clone.find('[id]').each(function () { this.id = this.id.replace(currentId, lastID) }); | ||
|
||
$clone.find('[for]').each(function () { this.setAttribute('for', this.getAttribute('for').replace(currentId, lastID)) }); | ||
|
||
$clone.each(function (i, e) { | ||
$("e:not(.form-elements)").each(function () { | ||
var newName = this.getAttribute('name'); | ||
newName = newName.substring(0, (newName.lastIndexOf('-') + 1)); | ||
newName = newName + ts.toString(); | ||
this.setAttribute('name', newName); | ||
}); | ||
|
||
}); | ||
|
||
$clone.find(".form-elements").find(":input").each(function () { | ||
if (this.getAttribute('name') == 'name') { | ||
var newVal = this.getAttribute('value'); | ||
newVal = newVal.substring(0, (newVal.lastIndexOf('-') + 1)); | ||
newVal = newVal + ts.toString(); | ||
this.setAttribute('value', newVal); | ||
} | ||
}); | ||
|
||
$clone.attr("id", lastID); | ||
$clone.attr("name", cloneName); | ||
$clone.addClass("cloned"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cloned fields with options like select and checkbox groups will need to have their options made sortable again. Adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Kevin. I did toy with that this morning and pushed that change. |
||
$('.sortable-options', $clone).sortable(); | ||
lastID = _helpers.incrementId(lastID); | ||
return $clone; | ||
}; | ||
|
||
// ---------------------- UTILITIES ---------------------- // | ||
|
@@ -1117,6 +1163,16 @@ | |
$(this).val(_helpers.forceNumber($(this).val())); | ||
}); | ||
|
||
// Copy field | ||
$sortableFields.on('click touchstart', '.icon-copy', function (e) { | ||
e.preventDefault(); | ||
var currentItem = $(this).parent().parent("li"); | ||
var $clone = cloneItem(currentItem); | ||
$clone.insertAfter(currentItem); | ||
_helpers.updatePreview($clone); | ||
_helpers.save(); | ||
}); | ||
|
||
// Delete field | ||
$sortableFields.on('click touchstart', '.delete-confirm', function(e) { | ||
e.preventDefault(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,7 @@ | |
a { | ||
&:hover { | ||
text-decoration: none; | ||
color: #000; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change order of action buttons? I think going from most used to least used from right to left makes sense but that would mean moving the delete button also. What are your thoughts? I ask mainly because I keep cloning fields when i mean to edit them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't have a preference. But anyone currently using formBuilder could be thrown off by flip-flopping edit and delete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I do like having delete in the upper right, since the behavior is similar to "close". I.e. closing a window or a dialog is typically done in the upper right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so then the question is should it be
[toggleBtn, copyBtn, delBtn]
or[copyBtn, toggleBtn, delBtn]
?I'm fine with it either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, let's leave it at
[toggleBtn, copyBtn, delBtn]
keeping the edit button on the left -- closest to the field attributes that need to be edited.