Programming terms - what's it called when you're continuously checking for the relevancy of an error message? [closed]

StackOverflow https://stackoverflow.com/questions/19941180

  •  30-07-2022
  •  | 
  •  

Question

The title may seem vague, let me elaborate. I've made a form in javascript that when submitted validates the input fields. When either of the 2 fields are invalid they get colored red. What I want to add now is a listener that checks whether the user has inputted the correct values (in real time, ie. without clicking the submit button). I need a good name for this function but can't come up with anything good...

Here's what I got so far:
checkRelevanceOfInvalidity()
checkStatusOfErrorMessage()

My current names for my functions:
function loadContentList()
function refreshGUI()
function addToContentList(title, rating)
function validateContent(title, rating)
function addContent()
function disableOption(pos)
function addEventListeners()
function init()
function devtest()

Était-ce utile?

La solution

Good method names are really important so its definitely worth thinking about.

It depends a bit on what valid means for each of the fields. If they are different then you could have something along the lines of:

  • validTitle()
  • validRating()

So, in the listener you would then do

if !validTitle()
    //highlight the title field 

It may also be useful to have a general method that calls each one and displays a general error.

  • searchFormIsValid()

The main listener function could be called

  • checkSearchForm()

In Angular this would be a watcher, so maybe even watchSearchForm()

Its good to try and break things down as much as possible and have each method doing as small a thing as possible.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top