diff --git a/README.md b/README.md index f37eb4d..1f3a642 100644 --- a/README.md +++ b/README.md @@ -172,8 +172,4 @@ add values to the form (such as specifying which action to take for the rest of [usability table for `SubmitEvent.submitter`](https://caniuse.com/mdn-api_submitevent_submitter) to check if your target browser is supported. -Setting form values of disabled elements is not supported by design, as `formxtra` is made for submittable form -elements. If a disabled element's value needs to be changed somehow, the form instance is already available, and the -element to be looked up is accessible via `HTMLFormElement.elements`. - The sources are under the [MIT license](https://code.modal.sh/TheoryOfNekomata/formxtra/raw/branch/master/LICENSE). diff --git a/cypress/integration/core.test.ts b/cypress/integration/core.test.ts index cee2013..1c960fd 100644 --- a/cypress/integration/core.test.ts +++ b/cypress/integration/core.test.ts @@ -336,6 +336,7 @@ describe('misc', () => {
@@ -409,6 +410,23 @@ describe('misc', () => { }, }) }); + + it('should allow setting values for disabled elements', () => { + utils.test({ + querySubmitter: (cy: any) => cy.get('[type="submit"]'), + onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { + let isThrown = false; + try { + setFormValues(form, { foobar: 'baz', disabled: 'new value' }, { includeDisabled: true }); + } catch (e) { + isThrown = true; + } + + expect(isThrown).toBe(false); + expect(getFormValues(form, { includeDisabled: true })).toEqual({ foobar: 'baz', disabled: 'new value', }); + }, + }) + }); }); @@ -430,6 +448,7 @@ describe('misc', () => { +