Add pin validation
This commit is contained in:
@@ -2,9 +2,24 @@ import type { BluetoothValidation } from "@app/validation/config/bluetooth.tsx";
|
|||||||
import { DynamicForm } from "@components/Form/DynamicForm.tsx";
|
import { DynamicForm } from "@components/Form/DynamicForm.tsx";
|
||||||
import { useDevice } from "@core/stores/deviceStore.ts";
|
import { useDevice } from "@core/stores/deviceStore.ts";
|
||||||
import { Protobuf } from "@meshtastic/js";
|
import { Protobuf } from "@meshtastic/js";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export const Bluetooth = (): JSX.Element => {
|
export const Bluetooth = (): JSX.Element => {
|
||||||
const { config, setWorkingConfig } = useDevice();
|
const { config, setWorkingConfig } = useDevice();
|
||||||
|
const [bluetoothValidationText, setBluetoothValidationText] = useState<string>();
|
||||||
|
|
||||||
|
const bluetoothPinChangeEvent = (
|
||||||
|
e: React.ChangeEvent<HTMLInputElement>,
|
||||||
|
) => {
|
||||||
|
if (e.target.value[0] == "0")
|
||||||
|
{
|
||||||
|
setBluetoothValidationText("Bluetooth Pin cannot start with 0.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setBluetoothValidationText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onSubmit = (data: BluetoothValidation) => {
|
const onSubmit = (data: BluetoothValidation) => {
|
||||||
setWorkingConfig(
|
setWorkingConfig(
|
||||||
@@ -52,6 +67,8 @@ export const Bluetooth = (): JSX.Element => {
|
|||||||
name: "fixedPin",
|
name: "fixedPin",
|
||||||
label: "Pin",
|
label: "Pin",
|
||||||
description: "Pin to use when pairing",
|
description: "Pin to use when pairing",
|
||||||
|
validationText: bluetoothValidationText,
|
||||||
|
inputChange: bluetoothPinChangeEvent,
|
||||||
disabledBy: [
|
disabledBy: [
|
||||||
{
|
{
|
||||||
fieldName: "mode",
|
fieldName: "mode",
|
||||||
|
|||||||
Reference in New Issue
Block a user