Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Define Rules

  • Last UpdatedNov 15, 2023
  • 1 minute read

Define rules for a custom control to validate the data using the client-side JavaScript.

To define custom control rules

  1. Override the Rules collection property in the custom control class.

  2. Define the rule name, rule definition, control type, and render mode, if required.

  3. At the client-side custom control JavaScript file, implement a JavaScript function with the following in mind:

  4. Use the same name for the JavaScript function as that of the rule name defined in the custom control class.

  5. Use the ControlControlValue and ruleObject for parameters.

  6. Verify the ControlValue parameter before taking any action.

  7. Get the rule definition message using ruleObject.ErrorMessage property.

Example: Custom Control Class

/// <summary>

/// Rules for the control

/// </summary>

public override Collection<Rule> Rules

{

get

{

Collection<Rule> rules = base.Rules;

string ruleName = "MinMaxNumberValidation";

string errorMessage = "$Name$ value is out of range.";

rules.Insert(0, new Rule { RuleFor = "Value", RuleName = ruleName, RuleDefinition = errorMessage,

ControlType = this.GetType().Name, RenderMode = this.RenderAs.ToString() });

return rules;

}

}

Example: Custom Control Client-side JavaScript

function minMaxNumberValidation(controlValue, control, ruleObject)

{

if (control.renderMode === "NonHtml5")

{

var errorMessage = "";

var errorBoolValue = false;

var errorCode = errorConstants.none;

var value = parseFloat(controlValue);

if (!isNaN(value))

{

if ((value >= control.min && value <= control.max) == false)

{

errorBoolValue = true;

errorCode = errorConstants.valueValidationRules;

control.validationError(errorBoolValue);

control.validationErrorMessage(Skelta.localize.getString(ruleObject.errorMessage).replace("$Name$", control.xmlNodeBoundTo.toString()));

control.validationErrorCode(errorCode);

}

}}

}

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in