Fix save button not activating when original setting started as null
This commit is contained in:
parent
1109c227e5
commit
a22fd26e4f
2 changed files with 24 additions and 11 deletions
|
@ -31,7 +31,7 @@ class DirtySubmitForm {
|
|||
updateDirtyInput(event) {
|
||||
const input = event.target;
|
||||
|
||||
if (!input.dataset.dirtySubmitOriginalValue) return;
|
||||
if (!input.dataset.isDirtySubmitInput) return;
|
||||
|
||||
this.updateDirtyInputs(input);
|
||||
this.toggleSubmission();
|
||||
|
@ -65,6 +65,7 @@ class DirtySubmitForm {
|
|||
}
|
||||
|
||||
static initInput(element) {
|
||||
element.dataset.isDirtySubmitInput = true;
|
||||
element.dataset.dirtySubmitOriginalValue = DirtySubmitForm.inputCurrentValue(element);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,35 @@
|
|||
import DirtySubmitForm from '~/dirty_submit/dirty_submit_form';
|
||||
import { setInput, createForm } from './helper';
|
||||
|
||||
function expectToToggleDisableOnDirtyUpdate(submit, input) {
|
||||
const originalValue = input.value;
|
||||
|
||||
expect(submit.disabled).toBe(true);
|
||||
|
||||
return setInput(input, `${originalValue} changes`)
|
||||
.then(() => expect(submit.disabled).toBe(false))
|
||||
.then(() => setInput(input, originalValue))
|
||||
.then(() => expect(submit.disabled).toBe(true));
|
||||
}
|
||||
|
||||
describe('DirtySubmitForm', () => {
|
||||
it('disables submit until there are changes', done => {
|
||||
const { form, input, submit } = createForm();
|
||||
const originalValue = input.value;
|
||||
|
||||
new DirtySubmitForm(form); // eslint-disable-line no-new
|
||||
|
||||
expect(submit.disabled).toBe(true);
|
||||
return expectToToggleDisableOnDirtyUpdate(submit, input)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
return setInput(input, `${originalValue} changes`)
|
||||
.then(() => {
|
||||
expect(submit.disabled).toBe(false);
|
||||
})
|
||||
.then(() => setInput(input, originalValue))
|
||||
.then(() => {
|
||||
expect(submit.disabled).toBe(true);
|
||||
})
|
||||
it('disables submit until there are changes when initializing with a falsy value', done => {
|
||||
const { form, input, submit } = createForm();
|
||||
input.value = '';
|
||||
|
||||
new DirtySubmitForm(form); // eslint-disable-line no-new
|
||||
|
||||
return expectToToggleDisableOnDirtyUpdate(submit, input)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue