|
1 | 1 | import $ from "jquery"; |
2 | 2 | import Base from "../../core/base"; |
| 3 | +import dom from "../../core/dom"; |
3 | 4 | import utils from "../../core/utils"; |
4 | 5 | import logging from "../../core/logging"; |
5 | 6 | import Parser from "../../core/parser"; |
@@ -34,6 +35,7 @@ export default Base.extend({ |
34 | 35 | } |
35 | 36 |
|
36 | 37 | let state = handler.evaluate(); |
| 38 | + this.set_input_state(state); |
37 | 39 | switch (options.action) { |
38 | 40 | case "show": |
39 | 41 | utils.hideOrShow($el, state, options, this.name); |
@@ -77,6 +79,28 @@ export default Base.extend({ |
77 | 79 | } |
78 | 80 | }, |
79 | 81 |
|
| 82 | + set_input_state(enabled) { |
| 83 | + // If not enabled, remove any `required` attributes on input fields. |
| 84 | + // Otherwise restore them. |
| 85 | + const inputs = dom.find_input(this.el); |
| 86 | + |
| 87 | + for (const el of inputs) { |
| 88 | + if (enabled) { |
| 89 | + const required = el.dataset.required; |
| 90 | + if (typeof required !== "undefined") { |
| 91 | + el.setAttribute("required", required); |
| 92 | + delete el.dataset.required; |
| 93 | + } |
| 94 | + } else { |
| 95 | + const required = el.getAttribute("required", null); |
| 96 | + if (required !== null) { |
| 97 | + el.dataset.required = required; |
| 98 | + el.removeAttribute("required"); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + }, |
| 103 | + |
80 | 104 | async onReset(event) { |
81 | 105 | const dependents = $(event.target).data("patDepends.dependents"); |
82 | 106 | await utils.timeout(50); |
@@ -130,6 +154,7 @@ export default Base.extend({ |
130 | 154 | const $depdendent = $(dependent); |
131 | 155 | const state = handler.evaluate(); |
132 | 156 |
|
| 157 | + this.set_input_state(state); |
133 | 158 | switch (options.action) { |
134 | 159 | case "show": |
135 | 160 | utils.hideOrShow($depdendent, state, options, this.name); |
|
0 commit comments