
Techinical Reference Personalized validation in JavaScript
How to personalize the validation form for a set of data entries.
Table of contents 1. The IModule Interface 2. Data Repository - AnyDataSet 3. Uploading Documents 4. Grouping data entries in XMLNuke 5. Personalized validation in JavaScript 6. Adding Pieces of JavaScript Code 7. Creating your own XML objects 8. Internationalization with XMLNuke. 9. Processing Events with the Click of a Button. 10. Automatically defining the values of Properties
On this page Creating your own JavaScript validation
Creating your own JavaScript validation
XMLNuke is able to validate data entry directly in the client browser through a JavaScript code. This validation is done automatically for various types of data ? Number, Text, Date ? in addition to whether the field is required, range of values, etc. All of this is defined through the properties in the XmlInputTextBox object. The JavaScript generated automatically by XMLNuke runs in any browser compatible with JavaScript.
However, in some cases, it is necessary to create personalized validations that should be executed in the client's browser. For this, we should define a JavaScript:
Example in CSharp
public override IXmlnukeDocument CreatePage()
{
// The XmlInputTextBox below will have a personalized JavaScript which it will run
// the "validacaoCustomizada" function at the moment of Submit.
XmlInputTextBox txt = new XmlInputTextBox("Label", "FieldName", "");
txt.setCustomJS("validacaoCustomizada");
.
.
.
string javascript =
"
function validacaoCustomizada(form, obj) {
// form -> DOM object of the form that set off the event
// obj -> DOM object of the form that set off the event
return ""; // <-- If returned other than EMPTY,
// XMLNuke understands ERROR.
}
";
this.defaultXmlnukeDocument.addJavaScriptSource(javascript, true);
}
Example in PHP
public function CreatePage()
{
// The XmlInputTextBox below will have a personalized JavaScript which it will run
// the "validacaoCustomizada" function at the moment of Submit.
$txt = new XmlInputTextBox("Label", "fieldname", "");
$txt->setCustomJS("validacaoCustomizada");
.
.
.
$javascript =
"
function validacaoCustomizada(form, obj) {
// form -> DOM object of the form that set off the event
// obj -> DOM object of the form that set off the event
return ""; // <-- If returned other than EMPTY,
// XMLNuke understands ERROR.
}
";
$this->defaultXmlnukeDocument->addJavaScriptSource($javascript, true);
}
|