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

Refactor javascript to allow overriding of createNewField() #65

Merged
merged 1 commit into from
Jan 16, 2015
Merged
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
Refactor javascript to allow overriding of createNewField()
Extracted createNewField() and _changeControlsToRemove() from
_newField()
  • Loading branch information
jcoyne committed Jan 16, 2015
commit 9cd01a4dc2b6f6f3c3cfc5c35066d3c794046ba9
25 changes: 18 additions & 7 deletions app/assets/javascripts/hydra-editor/manage_repeating_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,28 @@ var HydraEditor = (function($) {
}
},

_newField: function($activeField) {
var $removeControl = this.remover.clone(),
$activeFieldControls = $activeField.children('.field-controls'),
$newField = $activeField.clone();
$('.add', $activeFieldControls).remove();
$activeFieldControls.prepend($removeControl);
_newField: function ($activeField) {
var $newField = this.createNewField($activeField);
// _changeControlsToRemove must come after createNewField
// or the new field will not have an add button
this._changeControlsToRemove($activeField);
return $newField;
},

createNewField: function($activeField) {
$newField = $activeField.clone();
$newChildren = $newField.children('input');
$newChildren.val('').removeProp('required');
$newChildren.first().focus();
this.element.trigger("managed_field:add", $newChildren.first());
return $newField;
return $newField
},

_changeControlsToRemove: function($activeField) {
var $removeControl = this.remover.clone();
$activeFieldControls = $activeField.children('.field-controls');
$('.add', $activeFieldControls).remove();
$activeFieldControls.prepend($removeControl);
},

clearEmptyWarning: function() {
Expand Down