Refactor state input visibility and enable/disable logic

Introduced helper functions to hide/disable and show/enable state input sections, improving code readability and maintainability. All state inputs are now disabled when hidden and enabled when shown, ensuring correct form behavior.
这个提交包含在:
Peter Goodhall 2025-08-02 11:30:25 +01:00
父节点 41af9e04d7
当前提交 176291be45

查看文件

@ -44,8 +44,29 @@ $(document).ready( function () {
'6': 'us_state' // Alaska '6': 'us_state' // Alaska
}; };
// Hide all states initially /**
$("#canada_state, #aland_state, #asiatic_russia_state, #belarus_state, #mexico_state, #eu_russia_state, #argentina_state, #brazil_state, #chile_state, #us_state, #paraguay_state, #korea_state, #uruguay_state, #venezuela_state, #australia_state, #png_state, #nz_state, #belgium_state, #italy_state, #netherlands_state").hide(); * Helper function to hide and disable all state inputs
*/
function hideAllStates() {
$("#canada_state, #aland_state, #asiatic_russia_state, #belarus_state, #mexico_state, #eu_russia_state, #argentina_state, #brazil_state, #chile_state, #us_state, #paraguay_state, #korea_state, #uruguay_state, #venezuela_state, #australia_state, #png_state, #nz_state, #belgium_state, #italy_state, #netherlands_state")
.hide()
.find('input, select, textarea')
.prop('disabled', true);
}
/**
* Helper function to show and enable a specific state input
*/
function showState(stateId) {
$("#" + stateId)
.show()
.find('input, select, textarea')
.prop('disabled', false);
}
// Hide all states initially and disable their inputs
hideAllStates();
/** /**
* Gets the selected DXCC ID and shows the corresponding state. * Gets the selected DXCC ID and shows the corresponding state.
*/ */
@ -53,11 +74,11 @@ $(document).ready( function () {
var stateToShow = stateMap[selectedDXCCID]; var stateToShow = stateMap[selectedDXCCID];
if (stateToShow) { if (stateToShow) {
// Show the selected state // Show the selected state and enable its inputs
$("#" + stateToShow).show(); showState(stateToShow);
} else { } else {
// If no state matches the selected value, show 'us_state' by default // If no state matches the selected value, show 'us_state' by default
$("#us_state").show(); showState('us_state');
} }
/** /**
@ -66,12 +87,12 @@ $(document).ready( function () {
*/ */
$('#dxcc_select').change(function(){ $('#dxcc_select').change(function(){
var selectedValue = $(this).val(); var selectedValue = $(this).val();
var stateToShow = stateMap[selectedValue] || stateMap['default']; var stateToShow = stateMap[selectedValue] || 'us_state';
// Hide all states // Hide all states and disable their inputs
$("#mexico_state, #belarus_state, #asiatic_russia_state, #aland_state, #canada_state, #us_state, #eu_russia_state, #argentina_state, #brazil_state, #chile_state, #paraguay_state, #korea_state, #uruguay_state, #venezuela_state, #australia_state, #png_state, #nz_state, #belgium_state, #italy_state, #netherlands_state").hide(); hideAllStates();
// Show the selected state // Show the selected state and enable its inputs
$("#" + stateToShow).show(); showState(stateToShow);
}); });
} ); } );