Skip to content
New issue

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

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

Already on GitHub? # to your account

Bugfix: ensure there are field for clearFields action and update demo #245

Merged
merged 3 commits into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion demo/assets/js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ jQuery(document).ready(function($) {
editing = !editing;
};

$(buildWrap).formBuilder();
var formBuilder = $(buildWrap).formBuilder().data('formBuilder');

console.log(formBuilder);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give developers quick view of available actions, data etc


$('.form-builder-save').click(function(e) {
toggleEdit();
Expand Down
10 changes: 3 additions & 7 deletions demo/assets/js/form-builder.min.js

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions demo/assets/js/form-render.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/assets/js/form-render.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ gulp.task('deploy', () => {
console.log('Demo was successfully deployed!\n');
}
});
exec(`cd site && OVERCOMMIT_DISABLE=1 git add --all && OVERCOMMIT_DISABLE=1 git commit -am "${pkg.version}" && OVERCOMMIT_DISABLE=1 git push origin master && gulp deploy && cd ../`, function(err, stdout, stderr) {
exec(`cd site && gulp deploy && cd ../`, function(err, stdout, stderr) {
console.log(stdout);
if (stderr) {
console.error(err, stderr);
Expand Down
55 changes: 28 additions & 27 deletions src/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,30 +355,6 @@
$field.html(typeLabel).appendTo($cbUL);
}

let viewDataText = opts.dataType === 'xml' ? opts.messages.viewXML : opts.messages.viewJSON;

if (opts.showActionButtons) {
// Build our headers and action links
var viewData = utils.markup('button', viewDataText, {
id: frmbID + '-view-data',
type: 'button',
className: 'view-data btn btn-default'
}),
clearAll = utils.markup('button', opts.messages.clearAll, {
id: frmbID + '-clear-all',
type: 'button',
className: 'clear-all btn btn-default'
}),
saveAll = utils.markup('button', opts.messages.save, {
className: `btn btn-primary ${opts.prefix}save`,
id: frmbID + '-save',
type: 'button'
}),
formActions = utils.markup('div', [clearAll, viewData, saveAll], {
className: 'form-actions btn-group'
});
}

// Sortable fields
$sortableFields.sortable({
cursor: 'move',
Expand Down Expand Up @@ -432,7 +408,32 @@
var cbWrap = $('<div/>', {
id: frmbID + '-cb-wrap',
'class': 'cb-wrap ' + formBuilder.layout.controls
}).append($cbUL[0], formActions);
}).append($cbUL[0]);

if (opts.showActionButtons) {
// Build our headers and action links
let viewDataText = opts.dataType === 'xml' ? opts.messages.viewXML : opts.messages.viewJSON,
viewData = utils.markup('button', viewDataText, {
id: frmbID + '-view-data',
type: 'button',
className: 'view-data btn btn-default'
}),
clearAll = utils.markup('button', opts.messages.clearAll, {
id: frmbID + '-clear-all',
type: 'button',
className: 'clear-all btn btn-default'
}),
saveAll = utils.markup('button', opts.messages.save, {
className: `btn btn-primary ${opts.prefix}save`,
id: frmbID + '-save',
type: 'button'
}),
formActions = utils.markup('div', [clearAll, viewData, saveAll], {
className: 'form-actions btn-group'
});

cbWrap.append(formActions);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures formActions is within scope and is only appended if it exists

}

$stageWrap.append($sortableFields, cbWrap);
$stageWrap.before($formWrap);
Expand Down Expand Up @@ -1209,7 +1210,7 @@
});


if(opts.showActionButtons) {
if (opts.showActionButtons) {
// View XML
var xmlButton = $(document.getElementById(frmbID + '-view-data'));
xmlButton.click(function(e) {
Expand Down Expand Up @@ -1259,7 +1260,7 @@

document.dispatchEvent(formBuilder.events.loaded);

// Make some actions accessible
// Make actions accessible
formBuilder.actions = {
clearFields: _helpers.removeAllfields,
showData: _helpers.showData,
Expand Down
4 changes: 4 additions & 0 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@ function formBuilderHelpersFn(opts, formBuilder) {
var $fields = $(fields);
var markEmptyArray = [];

if (!fields.length) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dump out of the function if there are no fields to clear

return false;
}

if (opts.prepend) {
markEmptyArray.push(true);
}
Expand Down