Say I have a Person object. I need to ask the user to choose from a list, which laptop they have.
They can also choose the option "My product isn't listed here".
Now the Person object will look like:
{
name: 'John',
laptop: 'Dell'
}
If the user selects "My product isn't listed here", I can store it as:
laptop: 'OTHER'
But this is not recommended, as I shouldn't mix the laptop name string with the "other" string. In the code I'll be checking against the string "other", like a magic constant, which doesn't seem right.
I can't leave it as laptop: null
because then I wouldn't know if the user selected "other" or did not make a choice at all.
Another option is to have a separate field like:
{
name: 'John',
laptop: null,
laptopFoundInList: false
}
With this, I'll have to maintain 2 fields for the same thing.
I'm sure this is a very common problem. What's the correct convention to store such information?