It's all about the answers!

Ask a question

RTC: How to invalidate input inside validate:function


Marcelo Bilezker (4619) | asked Apr 20 '21, 1:49 p.m.
edited Apr 20 '21, 2:01 p.m.

 I check input inside validate function. 


If the input is not valid, and can not be restricted by configuration (it depends on values from other fields): 
How can i Invalidate it so it conserve the old value?

Checking variable Status, from 
var Status= com.ibm.team.workitem.api.common.Status;
i see I can return Status.OK_STATUS only, I dont found a Status.NOT_OK_STATUS to return.







Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Apr 21 '21, 2:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I was incorrect about validators, anyway, here is the documentation: https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Validators including the valid status information.

Marcelo Bilezker selected this answer as the correct answer

3 other answers



permanent link
Ralph Schoon (63.1k33645) | answered Apr 20 '21, 3:25 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Apr 20 '21, 3:28 p.m.
I am stunned that you seem to think anyone can do anything about your question with the information given.

Comments
Ralph Schoon commented Apr 20 '21, 3:27 p.m. | edited Apr 20 '21, 4:50 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

A validate can only validate to true or false, and only prevent saving. You can close your browser and start wit the old values.


Marcelo Bilezker commented Apr 20 '21, 8:19 p.m.

A validate function can also returns a number indicating the reason why it is not validating the input.  

Also, the validate function show as an example in eclipse, returns always Status.OK_STATUS


This return value suggests that there is another enumeration value that returns something else. 

If it only can return true or false, then why using an enumeration or a variable? It is confusing.
Thanks any way for your response.
 


permanent link
Marcelo Bilezker (4619) | answered Apr 20 '21, 9:23 p.m.
edited Apr 20 '21, 9:33 p.m.

Besides, checking the value of "Status.OK_STATUS" in the validate function, with the Developer Tool, show this:


{fSeverity: {...}, fMessage: ""}
etc...

So, Status.OK_STATUS is an object, very different of returning "true" or false

So, asking what must be returned when validation is not ok ,i think is a valid question


permanent link
Marcelo Bilezker (4619) | answered Apr 20 '21, 9:43 p.m.

 

Sorry about not being more specific before. I thought that validate function i referred to, is of common use. 
So, I hope now it will be more clear.

This is the code eclipse shows as an example of a validate function:

/***********
* Licensed Materials - Property of IBM
* (c) Copyright IBM Corporation 2011. All Rights Reserved.
*
* Note to U.S. Government Users Restricted Rights: 
* Use, duplication or disclosure restricted by GSA ADP Schedule
* Contract with IBM Corp.
***********
/
dojo.provide("com.example.Validator");

dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");

(function() {

var Severity= com.ibm.team.workitem.api.common.Severity;
var Status= com.ibm.team.workitem.api.common.Status;

    dojo.declare("com.example.Validator", null, {

        validate: function(attribute, workItem, configuration) {

                return Status.OK_STATUS;

        }
    });
})();

This function is called every time i change a value of some field
And this function, as an example, always returns OK_STATUS, which is an object.
So, my question now is, what must be returned when the status is not ok. Returning FALSE does not work

I hope is more clear now.


Comments
Ralph Schoon commented Apr 21 '21, 3:53 p.m. | edited Apr 21 '21, 3:54 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Yea, the example is a bit oversimplified. You would work with work item attribute values to validate.

I created https://jazz.net/library/article/1093 and the last two labs should give a better impression what you can do. Maybe you check that.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.