Introduction
To use Simbel
JS Generator just need
Java Runtime Environment 1.4 (or higher), you can download it from
java.sun.com.
After install JRE, you can run SJSG
typing:
$ java -jar
<simbel-pack-name>.jar
source.xml <destination.js>
SJSG read and
parse source.xml,
generating javascript code to destinacion.js; If destination file is
not defined or passed by argument, the default is simbel.js.
XML source
estructure
The source xml
file contains the HTML
from definition of your page. In this version only supports one form
definition by source file.
The root node
of the document must be
<simbelmyne>
</simbelmyne>
|
Between this
elements you must define
your form:
<form
name="formulario">
</form>
|
where name is
the HTML form name.
Form element
definition
Between form
tags you can define your
form elements and validation paramas, lake length, allow nulls..
Note: for this version only suport textarea and text fields.
<form-element
name="username"
type="text" accepted-chars="alpha">
</form-element>
|
In this case we
define a text field
named username (this name is the HTML form element name), and we
indicate that this element ‘only’ accept alpha
chars. We can define error messages if any
condition indicated for this element is bad. This definition must be
between <errors></errors> tags.
<errors>
<error type="onmax" message="The username is
long"/>
<error type="onmin" message="The username is
short"/>
<error type="onnull" message="This value is
null"/>
<error type="onbadchars" message="The text must
contain only alpha chars"/>
</errors>
|
We define four
errors:
-
On max : If
we define max length (maxlength) for this element, the message
‘The username is long’ must be displayed.
-
On min : If
we define min length (minlength) for this element, the message
‘The username is short’ will be displayed.
-
On null :
If we define allow null (allow-null) property for the element, the
message ‘The value is null’ will be displayed.
-
On bad
chars : If we defina specific chars (accepted-chars) for this element,
the code validates that the value of this element is a correct chars
type. If not, the message ‘The text must contain only alpha
chars’ will be displayed.
More params
We can validate
a login form:
<form-element name="password" type="text"
maxlength="10" minlength="1"
accepted-chars="alpha" allow-null="false"
>
<errors>
<error type="onmax" message="The password is
long"/>
<error type="onmin" message="The password is
short"/>
<error type="onnull" message="The password is
null"/>
<error type="onbadchars" message="The password must
contain alpha chars"/>
</errors>
</form-element>
|
This definition
indicates to SJSG
engine that must generate validation for a password element; the max
length is 10 and min length is 1, the valid chars is alpha (not
numeric o alphanumeric) and not be null.
Email validation
We can validate
email forms:
<form-element name="mail" type="mail"
allow-null="false" >
<errors>
<error type="onnull" message="The e.mail is
null"/>
<error type="oninvalidmail" message="You must type
a valid e-mail"/>
</errors>
</form-element>
|
|