-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Kastl <[email protected]>
- Loading branch information
Showing
7 changed files
with
448 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { generateChannelId } from "./utils"; | ||
|
||
/** | ||
* Get the values from the form using FormData API. | ||
*/ | ||
export function getFormValues() { | ||
const form = document.getElementById('meshtasticForm') as HTMLFormElement | null; | ||
|
||
if (!form) { | ||
throw new Error('Form element not found.'); | ||
} | ||
|
||
const formData = new FormData(form); // Pass the form to FormData | ||
|
||
// Extract form values and ensure the correct types | ||
const channelName = formData.get('channelName') as string; | ||
const pskType = formData.get('pskType') as string; | ||
const psk = formData.get('psk') as string; | ||
|
||
// FormData returns strings, so we need to parse the necessary fields | ||
const region = Number(formData.get('region')); | ||
const role = Number(formData.get('role')); | ||
const index = Number(formData.get('index')); | ||
const modemPreset = Number(formData.get('modemPreset')); | ||
const hopLimit = Number(formData.get('hopLimit')); | ||
|
||
const uplinkEnabled = formData.get('uplinkEnabled') === 'on'; // Checkbox returns 'on' or undefined | ||
const downlinkEnabled = formData.get('downlinkEnabled') === 'on'; | ||
const positionPrecision = Number(formData.get('positionPrecision')); | ||
const isClientMuted = formData.get('isClientMuted') === 'on'; | ||
|
||
const configOkToMqtt = formData.get('configOkToMqtt') === 'on'; | ||
const ignoreMqtt = formData.get('ignoreMqtt') === 'on'; | ||
|
||
// Handle default value for channelId | ||
const channelId = formData.get('channelId') as string || generateChannelId(); | ||
|
||
return { | ||
channelName, | ||
pskType, | ||
psk, | ||
region, | ||
role, | ||
index, | ||
modemPreset, | ||
hopLimit, | ||
channelId, | ||
uplinkEnabled, | ||
downlinkEnabled, | ||
positionPrecision, | ||
isClientMuted, | ||
configOkToMqtt, | ||
ignoreMqtt, | ||
}; | ||
} |
Oops, something went wrong.