Skip to content

Commit

Permalink
FIO-9034 fixed creating extra submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaKurban authored and lane-formio committed Sep 19, 2024
1 parent 9852a64 commit 820b011
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,12 @@ export default class WebformBuilder extends Component {
}
this.keyboardActionsEnabled = keyboardActionsEnabled;

const isSubmitButton = (comp) => {
return (comp.type === 'button') && ((comp.action === 'submit') || !comp.action);
}

const isShowSubmitButton = !this.options.noDefaultSubmitButton
&& (!form.components.length || !form.components.find(comp => comp.key === 'submit'));
&& (!form.components.length || !form.components.find(comp => isSubmitButton(comp)));

// Ensure there is at least a submit button.
if (isShowSubmitButton) {
Expand Down
12 changes: 12 additions & 0 deletions src/WebformBuilder.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import sameApiKeysLayoutComps from '../test/forms/sameApiKeysLayoutComps';
import testApiKeysUniquifying from '../test/forms/testApiKeysUniquifying';
import formBasedOnWizard from '../test/forms/formBasedOnWizard';
import formWithFormController from '../test/forms/formWithFormController';
import simpleWebform from '../forms/simpleWebform';

global.requestAnimationFrame = (cb) => cb();
global.cancelAnimationFrame = () => {};
Expand Down Expand Up @@ -233,6 +234,17 @@ describe('WebformBuilder tests', function() {
}).catch(done);
});

it('Should not add extra submit button if submit button API key was changed', (done) => {
const builder = Harness.getBuilder();
builder.setForm(simpleWebform).then(() => {
const components = builder.webform.components;
const submit = components[1];
assert.equal(components.length, 2);
assert.equal(components[1].key, 'testSubmit');
done();
}).catch(done);
});

it('Should keep min/max date validation settings with moment.js function', (done) => {
const builder = Harness.getBuilder();
builder.setForm(columnsForm).then(() => {
Expand Down
23 changes: 23 additions & 0 deletions test/forms/simpleWebform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
components: [
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
validateWhenHidden: false,
key: 'textField',
type: 'textfield',
input: true
},
{
type: 'button',
label: 'Submit',
key: 'testSubmit',
disableOnInvalid: true,
input: true,
tableView: false
}
],
display: 'form',
type: 'form',
};

0 comments on commit 820b011

Please sign in to comment.