|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IPluginValidator
Interface that makes it possible to implement a custom validator.
A class that implements this interface will be called when the question edit screen is loaded. A
simple setup will be added to the question edit screen, while an advanced setup screen appears as
a popup window when clicking on the provided link.
Field Summary | |
---|---|
static int |
CUSTOM_VALIDATOR_QUESTION
Validator type: Custom validator for question |
Method Summary | |
---|---|
boolean |
canValidate(int customValidatorType)
Returns whether the plugin can validate the type of validation, or not |
java.lang.String |
getAdvancedHTML(java.util.HashMap settings)
Returns the advanced HTML setup to be placed in a popup window when user click on link in the question edit screen. |
java.lang.String |
getErrorMessage(java.util.HashMap settings)
Gets the errorMessage to show from the settings hashmap. |
java.lang.String |
getJavaScriptFunction(int questionNo,
java.util.HashMap settings)
Gets the javaScriptFunction code for client side validation For example, for a plugin called FreeTextValidatorPlugin the returning javascript function call could be: |
java.lang.String |
getJavaScriptFunctionCall(int questionNo,
java.util.HashMap settings)
Gets the javaScriptFunctionCall name for client side validation This method must return a complete function call, including the function name and the parameters signature. |
java.lang.String |
getSimpleHTML(java.util.HashMap settings)
Returns the simple HTML setup to be placed in the question edit screen. |
boolean |
validate(long sId,
int qNo,
long respId,
java.util.HashMap settings)
Validates the question based on the attributes and values set in the settings hashmap |
Field Detail |
---|
static final int CUSTOM_VALIDATOR_QUESTION
Method Detail |
---|
boolean canValidate(int customValidatorType)
customValidatorType
- The type of custom validation
boolean validate(long sId, int qNo, long respId, java.util.HashMap settings)
sId
- Survey idqNo
- Question numberrespId
- Respondent idsettings
- Attributes and values settings
java.lang.String getSimpleHTML(java.util.HashMap settings)
<table> <tr> <td> Free text max length: <INPUT TYPE=text name="FreeTextValidatorPlugin_freeTextMaxLength" value=""> </td> <td> Custom error message: <INPUT TYPE=text name="FreeTextValidatorPlugin_errorMessage" value=""> </td> </tr> </table>Value for each of the input fields will be stored in the settings attribute, and the input fields should be filled with the typed in values. Make use of HtmlUtils.htmlEncode(String value) when getting input values from user. This will encode input value and avoid errors caused by users typing in unwanted characters that could affect the original html page. NOTE: A field for a custom error message is useful when you want to customize the error message for each question. Be also aware of that only one error message is allowed for a validator.
settings
- Attributes and values settings
java.lang.String getAdvancedHTML(java.util.HashMap settings)
<table> <tr> <td> Free text max length: <INPUT TYPE=text name="FreeTextValidatorPlugin_freeTextMaxLength" value=""> </td> </tr> <tr> <td> Word required: <INPUT TYPE=text name="FreeTextValidatorPlugin_wordRequired" value=""> </td> </tr> <tr> <td> Custom error message: <INPUT TYPE=text name="FreeTextValidatorPlugin_errorMessage" value=""> </td> </tr> </table>Value for each of the input fields will be stored in the settings attribute, and the input fields should be filled with the typed in values. Make use of HtmlUtils.htmlEncode(String value) when getting input values from user. This will encode input value and avoid errors caused by users typing in unwanted characters that could affect the original html page. NOTE: A field for a custom error message is useful when you want to customize the error message for each question. Be also aware of that only one error message is allowed for a validator. For advanced setup the error message should be a combination of all the possible validation errors.
settings
- Attributes and values settings
java.lang.String getErrorMessage(java.util.HashMap settings)
settings
- Attributes and values settings
java.lang.String getJavaScriptFunctionCall(int questionNo, java.util.HashMap settings)
checkMaxLengthAndRequiredWord(form.q1_freetext, 20, 'objectplanet')For the function call above, the parameter "form.q1_freetext" says which input field to validate, in this case the free text input field for question 1. Next, the number 20 indicates how many characters the free text is allowed to have. Finally, the string parameter says what word the free text should include, in this case the word "objectplanet". NOTE: The HTML utility class for the plugins, HtmlUtils, should be used to get the name of input fields to validate. In addition, make use of HtmlUtils.htmlEncode(String value) when getting input values from user. This will encode input value and avoid errors caused by users typing in unwanted characters that could affect the original html page.
java.lang.String getJavaScriptFunction(int questionNo, java.util.HashMap settings)
function checkMaxLengthAndRequiredWord(field, maxLength, wordRequired) { if(field != null){ if(field.value != null){ if(field.value.length > 0){ if(maxLength > 0 && field.value.length > maxLength){ return false; } if(wordRequired != null && field.value.indexOf(wordRequired) < 0){ return false; } } } } return true; }
|
Copyright ? ObjectPlanet Inc. All Rights Reserved. | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |