But when I use my custom node at runtime. If I leave the secret token input empty, and then 'Done' from edit, there is not something for error notification. For example, display a red triangle on my customer node to indicate that no input values have been entered.
So, How can I raise error at 'oneditsave' when my credential is empty?
Such as, show red triangle sign or something for notification to user, There are some error in my custom node. Please suggest me.
Ok. Now I can validate when 'oneditprepare'. But if I want to validate when drag node into flow, are there any solution for varidation before checking 'oneditprepare'?
There is a way to do things when dropping a node onto your flow and even before the first deploy for that node.
Here is an example from the next version of uibuilder:
/** Track which urls have been used - required to handle copy/paste and import
* as these can contain duplicate urls before deployment.
*/
RED.events.on('nodes:add', function(node) {
if ( node.type === 'uibuilder') {
// Keep a list of uib nodes in the editor
// may be different to the deployed list
editorInstances[node.id] = node.url
// -- IF uibuilderInstances <> editorInstances THEN there are undeployed instances. --
}
})
That code goes in the javascript script in your html file. It goes outsideRED.nodes.registerType and it is set up maybe even when a node is added to the palette, can't quite remember. Anyway, put some console log statements in so that you can see when it is triggered. Obviously, the RED.events.on('nodes:add', function(node) {}) function is triggered when ANY node is added so make sure you include a test to limit to just the node type you are interested in.
Whilst that does give you hook into the event of when a node is added to the workspace, it doesn't let you do any custom validation of the node - there's no way to mark a node as invalid so it displays an error. We don't provide any way to do custom validation beyond the individual validate functions on the properties - and you can't have those functions on credential type properties.
I've already linked to the backlog item to let you to mark a credential as required (which doesn't require knowledge of its actual value).
We already have another backlog item to let a node provide a custom validate function that isn't tied to an individual property.
Thank you very much for your reply again.
I try to use RED.events.on('nodes:add', function(node) {})
outside registerType. It can use console.log("Test") for displaying "Test" text.
But when I use jQuery for access input 'token', the result is 'undefined'.
You can't use jQuery there because the context is different at that point. The config panel for your node does not exist when that event fires. The node exists so you can certainly check it's current settings values but the config panel does not exist - so it doesn't make sense to check if any values have been changed by the user in the UI at that point because they can't be.
I use it to make sure that none of the URL's across multiple instances of uibuilder are duplicates reguardless - if you were to add 10 instances of uibuilder and not deploy between adding each, you could end up with multiples of the same URL which would cause problems.
Now I can use temporary solution by using input 'checkbox' for help.
I set default value 'false' for this checkbox'.
And I set validate function for this checkbox is return its value directly.
Then, at 'oneditsave' event,
I add algorithm for checking input 'token', which it has value or not?
If input token has value, then I use jQuery for set checkbox 'check' -> then its value is true.
But if input token has not value, then I use jQuery for set checkbox 'check' -> then its value is false.