intra-mart Accel Kaiden! / Programming Guide

«  Master Search Parts   ::   Contents   ::   Inter-gadget Communication  »

Validation

Client validation in intra-mart Accel Kaiden! extends ”jQuery Validation Plugin”.
Implementation method of client validation and others are introduced in this section.

Specification and Execution of Validation Rule

It specifies a validation of mandatory and maximum number of characters (100 characters) for the project code text box.
<k:codeText name="projectCd"
            mode="0"
            surfaceKey="project code"
            validationSave="{k_required:[''], k_maxLength:[100]}"/>
It executes validation by validation key "save", which is described later, for all gadgets.
var result = KAIDEN.gadgetMan.validate("save");

Notes

In order to execute validation, target element should be placed inside the <form>.

Validation Key

Validation key manages validation unit. This is effective when you want to do different validation on Validtion key is used to manage validation unit. For example, this is effective when you want to perform different validation for the save and the draft save.
For example, the following specify each different validation by validation key called "save" and validation key called "draft".
<k:codeText name="projectCd"
            mode="0"
            surfaceKey="project code"
            validationSave="{k_required:[''], k_maxLength:[100]}"
            validationDraft="{k_maxLength:[100]}"/>
When you execute the validation, each different validation can be executed by passing the validation key to the argument of KAIDEN.gadgetMan.validate().
// Process when save button is pressed
var resultDefaultValidate = KAIDEN.gadgetMan.validate("save");

// ~omitted~

// Process when draft save button is pressed
var resultDraftValidate   = KAIDEN.gadgetMan.validate("draft");

Notes

Validation key to be specified by JPS (tab lib) takes validation + validation key format.
When you execute the validation by javascript, validation keys are all specified in small letter.

Validation Escalation

In the above description, different validation from save/draft save is specified, but for k_maxLength:[100] both of them are checked in common.
Mechanism to avoid such checking redundancies is provided.

For "default", only the differences are specified in each validation by specifying common checks as follows.
<k:codeText name="projectCd"
            mode="0"
            surfaceKey="item code"
            validationDefault="{k_maxLength:[100]}"
            validationSave="{k_required:['']}"
            validationDraft=""/>
When the validation is executed, true is specified to the second argument of KAIDEN.gadgetMan.validate().
Then, validation contents of "default" is executed in addition to the validation specified by the validation key.
// Process when save button is pressed
var resultDefaultValidate = KAIDEN.gadgetMan.validate("save", true); //validation is executed in order of mandatory, the maximum character (100 characters)

// ~omited~

// Process when draft save button is pressed
var resultDraftValidate   = KAIDEN.gadgetMan.validate("draft", true); //validation is executed only for the maximum character (100 characters)

Original Validation Creation

When you create original validation, please use KAIDEN.validator.addValidateMethod() that registers validation itself and KAIDEN.validator.setInvalidMessage() that registers error message.

KAIDEN.validator.addValidateMethod("validation rule", function(value, element, param) {
  var rv = true;
  //validation contents *it will be error if false is returned.
  return rv;
});
KAIDEN.validator.setInvalidMessage("validation rule", function(arg, element) {
  return KAIDEN.validator.formatMessage("error message", element);
});

Notes

KAIDEN.validator.formatMessage() is optimized to be displayed on error Dialog as follows.
../../../_images/validation_error_dialog.png

Notes

By specifying the parameter to the third argument of KAIDEN.validator.formatMessage(), replacement character string ({0} or {1}) of the message can be replaced.

Item Name of Validation

Item names that are enclosed in the rectangle below in the error Dialog have errors.
../../../_images/validation_error_dialo_closeup.png
This item name uses surfaceKey property of text box and so on.
<k:codeText name="projectCd"
            mode="0"
            surfaceKey="item code"
            validationDefault="{k_maxLength:[100]}"
            validationSave="{k_required:['']}"
            validationDraft=""/>

Notes

If you specify the key, surfaceKey can generate the name from the property file for internationalization support items.

«  Master Search Parts   ::   Contents   ::   Inter-gadget Communication  »