Simple flow with very little code for resetting a "Passwords do not match" error message, in Node-red

34 Views Asked by At

My flow: Creates a UI-form with fields "email," "password," and "confirm"; Saves valid submissions to an sqlite database. But malfinctions when alerting the user if passwords are mismatched.

In order to alert the user when they try to create an account with mismatched passwords:

First, I send the msg.payload to a function. This function:

if (msg.payload.password !== msg.payload.confirm) {
    return { payload: "The passwords do not match" };
} else {
return msg; // Continue with the original msg object
}

Then, this msg is connected to a switch node that chooses whether to pass valid data to the server or a mismatched error to the user through a UI-text node.

The switch and the message work, as data does not save unless it passes the mismatch checkpoint, and the message displays after giving a test. The UI-text, once enabled, seems to stay on permanently even after resetting the entire server, however, I found a bandaid.

The best solution I have found to this is to set a trigger node, on a separate line from the same swtich node to the same UI-text. The error message is sent immediately through the first line and then displayed for 5 seconds in red. The trigger delays 5 seconds then sends " ", which clears the text desirably. Albeit, in the spirit of "Whack-a-mole".

I know it would be so much better to alert the user before they send the message. The only way I can think to do this might be installing jquery or implementing angular - anything that might be able to select the values of the form and compare them client-side. Neither, I know much about.

I noticed a similar article from someone who is not using UI nodes. This person seemed to achieve their solution by scripting the entire page with the necessary ids on each field. I almost did not submit this question because our problem is so similar, but I intend to use nodes and have enough of a solution that it might be useful for anyone who was in my shoes a couple hours ago.

I wouldn't want to write HTML unless it is impossible to achieve the result any other way, simply for ease of revision and convenience to my employees who don't know much about programming. There's probably a better solution, but I'm new to this. Any advice would be much appreciated.

0

There are 0 best solutions below