Skip to content

Commit b02767a

Browse files
committed
Toggle visibility for static/dynamic bridged AP options
1 parent cac6b21 commit b02767a

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

app/js/ui/hostapd.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export function initHostapd() {
2727
load80211wSelect();
2828

2929
const bridgeCheckbox = document.getElementById('chxbridgedenable');
30+
const dynamicIpCheckbox = document.getElementById('chxbridgedynamic');
3031
const bridgeSection = document.getElementById('bridgeStaticIpSection');
32+
const staticIpFields = document.getElementById('bridgeStaticIpFields');
3133
const staticIpInput = document.getElementById('bridgeStaticIp');
3234
const netmaskInput = document.getElementById('bridgeNetmask');
3335
const gatewayInput = document.getElementById('bridgeGateway');
@@ -36,16 +38,35 @@ export function initHostapd() {
3638

3739
const bridgeInputs = [staticIpInput, netmaskInput, gatewayInput, dnsInput];
3840

39-
// toggle visibility and required fields
41+
function applyStaticIpVisibility(isDynamic) {
42+
if (staticIpFields) {
43+
staticIpFields.style.display = isDynamic ? 'none' : 'block';
44+
}
45+
bridgeInputs.forEach(input => {
46+
if (input) {
47+
isDynamic ? input.removeAttribute('required') : input.setAttribute('required', 'required');
48+
}
49+
});
50+
}
51+
52+
// initialize static IP field state on page load
53+
if (dynamicIpCheckbox) {
54+
applyStaticIpVisibility(dynamicIpCheckbox.checked);
55+
dynamicIpCheckbox.addEventListener('change', function() {
56+
applyStaticIpVisibility(this.checked);
57+
});
58+
}
59+
60+
// toggle visibility and required fields for the whole bridge section
4061
if (bridgeCheckbox) {
4162
bridgeCheckbox.addEventListener('change', function() {
42-
if (this.checked) {
43-
bridgeSection.style.display = 'block';
44-
bridgeInputs.forEach(input => input.setAttribute('required', 'required'));
45-
} else {
46-
bridgeSection.style.display = 'none';
47-
bridgeInputs.forEach(input => input.removeAttribute('required'));
48-
}
63+
if (this.checked) {
64+
bridgeSection.style.display = 'block';
65+
applyStaticIpVisibility(dynamicIpCheckbox && dynamicIpCheckbox.checked);
66+
} else {
67+
bridgeSection.style.display = 'none';
68+
bridgeInputs.forEach(input => { if (input) input.removeAttribute('required'); });
69+
}
4970
});
5071
}
5172

0 commit comments

Comments
 (0)