JustJoostNL / F1MV-Lights-Integration

The best way to connect your smart home lights to MultiViewer.
https://f1mvli.jstt.me
GNU General Public License v3.0
24 stars 9 forks source link

added is-ip and helperText to softly validate input #39

Closed marcoka2000 closed 1 year ago

marcoka2000 commented 1 year ago

Added a subtle helperText which softly validates if it looks a valid IPv4 address

IPv4-quickfix

LapsTimeOFF commented 1 year ago

In my opinion, the code can be optimized:

const regex = /^(?:\d{1,3}\.){3}\d{1,3}$/gm

See in action here

  return (
    <TextField
      error
      id="wled-device-ip-input"
      label="WLED Device IP"
      color="secondary"
      variant="outlined"
      value={ipInput}
      onChange={(event) => setIpInput(event.target.value)}
      helperText={
        isIPv4(ipInput)
          ? '✔ This looks fine.'
          : 'Please use the IPv4 format xxx.xxx.xxx.xxx'
      }
    />
  );

And according to my proposition above, isIPv4 would use a function within this file and not using an external module.

Documentation reference

marcoka2000 commented 1 year ago

@LapsTimeOFF Hey, I just quickly wanted to say thanks for the good explanation, as someone who is not so fluent with all the newer React Frameworks I learned more from your detailed comment, than I did while tinkering on my own yesterday for several hours 👍

(Actually, this was exactly the outcome I tried to achieve, so the explanation is even more valuable to me 💯 )