JS - reset correctly radio buttons
This commit is contained in:
parent
4b49db7c95
commit
c01ef24541
@ -1002,7 +1002,6 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||||||
if (value) {
|
if (value) {
|
||||||
element.setAttribute("checked", true);
|
element.setAttribute("checked", true);
|
||||||
}
|
}
|
||||||
element.setAttribute("pdfButtonValue", data.buttonValue);
|
|
||||||
element.setAttribute("id", id);
|
element.setAttribute("id", id);
|
||||||
|
|
||||||
element.addEventListener("change", function (event) {
|
element.addEventListener("change", function (event) {
|
||||||
@ -1016,19 +1015,16 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.enableScripting && this.hasJSActions) {
|
if (this.enableScripting && this.hasJSActions) {
|
||||||
|
const pdfButtonValue = data.buttonValue;
|
||||||
element.addEventListener("updatefromsandbox", event => {
|
element.addEventListener("updatefromsandbox", event => {
|
||||||
const { detail } = event;
|
const { detail } = event;
|
||||||
const actions = {
|
const actions = {
|
||||||
value() {
|
value() {
|
||||||
const fieldValue = detail.value;
|
const checked = pdfButtonValue === detail.value;
|
||||||
for (const radio of document.getElementsByName(event.target.name)) {
|
for (const radio of document.getElementsByName(event.target.name)) {
|
||||||
const radioId = radio.getAttribute("id");
|
const radioId = radio.getAttribute("id");
|
||||||
if (fieldValue === radio.getAttribute("pdfButtonValue")) {
|
radio.checked = radioId === id && checked;
|
||||||
radio.setAttribute("checked", true);
|
storage.setValue(radioId, { value: radio.checked });
|
||||||
storage.setValue(radioId, { value: true });
|
|
||||||
} else {
|
|
||||||
storage.setValue(radioId, { value: false });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
focus() {
|
focus() {
|
||||||
|
@ -481,6 +481,9 @@ class RadioButtonField extends Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set value(value) {
|
set value(value) {
|
||||||
|
if (value === null) {
|
||||||
|
this._value = "";
|
||||||
|
}
|
||||||
const i = this.exportValues.indexOf(value);
|
const i = this.exportValues.indexOf(value);
|
||||||
if (0 <= i && i < this._radioIds.length) {
|
if (0 <= i && i < this._radioIds.length) {
|
||||||
this._id = this._radioIds[i];
|
this._id = this._radioIds[i];
|
||||||
|
@ -174,9 +174,15 @@ describe("Interaction", () => {
|
|||||||
it("must reset all", async () => {
|
it("must reset all", async () => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pages.map(async ([browserName, page]) => {
|
pages.map(async ([browserName, page]) => {
|
||||||
|
// click on a radio button
|
||||||
|
await page.click("[data-annotation-id='449R']");
|
||||||
|
|
||||||
// this field has no actions but it must be cleared on reset
|
// this field has no actions but it must be cleared on reset
|
||||||
await page.type("#\\34 05R", "employee", { delay: 200 });
|
await page.type("#\\34 05R", "employee", { delay: 200 });
|
||||||
|
|
||||||
|
let checked = await page.$eval("#\\34 49R", el => el.checked);
|
||||||
|
expect(checked).toEqual(true);
|
||||||
|
|
||||||
// click on reset button
|
// click on reset button
|
||||||
await page.click("[data-annotation-id='402R']");
|
await page.click("[data-annotation-id='402R']");
|
||||||
|
|
||||||
@ -194,6 +200,9 @@ describe("Interaction", () => {
|
|||||||
|
|
||||||
const sum = await page.$eval("#\\34 27R", el => el.value);
|
const sum = await page.$eval("#\\34 27R", el => el.value);
|
||||||
expect(sum).toEqual("");
|
expect(sum).toEqual("");
|
||||||
|
|
||||||
|
checked = await page.$eval("#\\34 49R", el => el.checked);
|
||||||
|
expect(checked).toEqual(false);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user