@artimys
Posted
Great job!! ππ You did a good job with your JS. Different functions to hold your regex validation. Event listener and good technique of using a css class name to enable your error styles.
-
I can see why you added a set timeout to for your input error handling. If you want to keep that effect I recommend to just disabled the button when clicked and then enable it when the user types a valid format in the input box. A bit more code with a javascript
keyup
event with asetTimeout
to delay the capture of user input can help prevent spamming the button (and redundant API calls). -
Another suggestion I can add is the arguments to your
getData()
function. Set it for only one default argument. It can default to
function getData(inputValue, searchType = 'IP') {
// write a condition where if searchType equals 'IP' append to your fetch URL
// else if 'DOMAIN' then append to your fetch URL
}
// will search by IP query by default
getData(myInput.value)
// will search by Domain query
getData(myInput.value, 'DOMAIN')
Hope it helps and keep on coding π
@NDOY3M4N
Posted
@artimys thanks for the feedbacks, Iβll try to add those functionalities. Also I wanted to ask if thereβs an easy way to position the search-results. I tried margin-bottom: 50% but it was not working the way I expected it to.
@artimys
Posted
@NDOY3M4N I found the search-results position tricky myself just because it shouldn't have a set height.
I made a codepen of my approach. I'm pretty sure there other easier ways but I don't think this is one lol.
@NDOY3M4N
Posted
@artimys yes indeed, if the box had a fixed height solving the problem wouldβve been easier. Guess Iβll just live with that π. But thanks again for your advices.