cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
849
Views
0
Helpful
9
Replies

How to mimic the 'mandatory' functionality

Miriam Rubin
Level 1
Level 1

When I set a field to mandatory, and subsequently hit 'Submit', the fields(s) are all highlighted at once, with 'Please complete the mandatory field before submitting'.

How can I replicate that in javascript since my criteria for mandatory is a little more complex?

9 Replies 9

Setting a field to mandatory using either the Mandatory action in a conditional rule or a set.Manadatory javascript function will cause the system to validate those fields when the form is submitted, and will display that behavior for any empty field.

Miriam Rubin
Level 1
Level 1

Let me clarify. I do not wish to make a field that is empty mandatory. We have drop downs that we typically put '- - -' in the first choice instead of all blanks which are not possible in newscale. before submittal, i run javascript that goes through all my dictionaries, and searches for fields that are mandatory, of type 'dropdown'(select), and contain '- - -' and then it throws an alert with all fields that satisfy this criteria. What I would LIKE would be if it could highlight it the same way other mandatory fields work, where they are all highlighted at once. this would remove the necessity for an alert itemizing all field names and thus be transparent to the user. at this point i can only focus on 1 field at a time, and i do not know how to highlight serveral. how can this be done?

Tylor Hagerman
Level 1
Level 1

You need to use the undocumented "addValidator" method.  Its usage is described in the ISF Training guide.  Also search for "addValidator" on this site and there will probably be a few other messages about it.

Tylor Hagerman
Level 1
Level 1

Oh, and please submit an enhancement request that select contol mandatory validation should be built into the product.  It is crazy that every customer on every form that includes a selection list needs to add custom validation code.  There should be an option in ServiceDeisgner to treat the first item in the list as "not filled out" and RC should take care of the rest.

Miriam Rubin
Level 1
Level 1

Or at least allow the user to use a #DEFINE where they allocate certain values to be synonymous with the concept of a blank field. I agree, it should be in the code. Have you used this addValidator method? will this highlight all the 'user-defined-mandatory' fields upon submission? I haven't tried this, but will. thanks for the advice!

Miriam,

I have uploaded a PDF with the slides from the ISF training that Tylor referred to:

Miriam Rubin
Level 1
Level 1

Thank you for the slides. I will try them out. However, wouldn't it be a *drop* safer if the statement for setting mandatory did not termporarily blank out field values, but just *checked* for them.

For example, I used this:

var myString = currentField.id;
            var myrealString = myString.toString();             

//assumptions:

// field names that I have in my dictionaries do NOT have ANY underscore in them

// the value of our fields is not '-- Please Select--' but '- - -'. (that can be substituted)

 

if ((myrealString.search("_") == -1) && ((currentField.getInputType()== "select") && currentField.isMandatory() && currentField.getValue() == "- - -"))

 

doing global replaces seems a  little scary, otherwise.

Miriam Rubin
Level 1
Level 1

Also, can you please explain each of the parameters for addValidator?

parameter 1 = 'null' what does this signify

parameter 2 = true, what does that signify

parameter 3: string 'Please fill out....' I assume that this is the instructional (help ) text that is replaced with this string; is there a way of preserving the help text and APPENDING this string to it? if the user didn't fill it out, there is a good chance they dont know WHAT to fill it out with, and replacing vital help info with standardized mandatory text seems to defeat the purpose.

Please advise.

Thanks

Feel free to experiment and/or reverse engineer the addValidator code  (it's in a JavaScript library under RequestCenter.war) if you want to figure out what the parameters do. I think that addValidator was originally intended to be more robust, and to allow user-specified validation, but that functionality was never implemented. Therefore, the "null" and true are pretty much the only values that work in these parameters. 

As for building up a dynamic error  message, you could probably do that by clearing out existing validators (hmm, Tylor, didn't I once find you the code for that? something like serviceForm.dictionary.field.validators = '') and building the desired string via JavaScript. This functionality would need to be fired in an onChange event, however, or some time before the onSubmit event.  Typically, the addValidator is just done in an onLoad event to set up validation considered to be unchanging throughout the life of the service form.