FormValidator

(esrith/amos/form/FormValidator)

FormValidator class checks all form elements that they are filled correctly according to corresponding rules before submission to the server.

Description
new FormValidator(params?srcNodeRef?)

Create a new FormValidator widget.

Description
ENCTYPE_FORM

"application/x-www-form-urlencoded" used with form.

ENCTYPE_UPLOAD

"multipart/form-data" used with upload.

Type Description
_styleAttr Object

when you want to set style for other node. you can do this by example... _styleAttr:{ style-property:effected-node } this property was effected where this class was inherited and your widget was called by... var widget = new YourWidget({ style:{ style-property:style-value } }); now effected-node in you widget will have style-property = style-value

action String

Specifies where to send the form data when a form is submitted.

active Boolean

If true, this forces the control to enter the active state and classname 'amos-form-active' will be added.

afterSubmit Function

Specifies the function that want to do after submit.

autoFocusOnError Boolean

If true, element that error has focus automatically.

beforeSubmit Function

Specifies the function that want to do before submit.

busy Boolean

If true, this forces the control to enter the busy state and classname 'amos-form-busy' will be added.

controls Object[]

List of control in a form.

dataStore DataStore | Object[] | String

A data store is a repository of a set of data objects.

disabled Boolean

If true, any control's events(except change) are not responding. Its content cannot be edited and is excluded when the form is submitted.

enctype String

Encoding type for the form (use constant).

error Boolean

If true, this forces the control to enter the error state and classname 'amos-form-error' will be added.

errorMessageVisible Boolean

Can Specifies the error message to hide or show.

filled Boolean

A flag that shows whether a form element is filled in (true) or empty (false).

invalidMessage String

Text of invalidMessage.

label String

Label of an element.

messageNode Node

The element that used to display error message.

method String

HTTP method used to submit the form, either "GET" or "POST".

name String

Name of form for scripting.

readOnly Boolean

If true, the control is read-only and cannot be edited. However, its content, if presents, is included in form submission.

target String

Target frame for the document to be opened in.

valid Boolean

Validity flag that shows whether a form element is validated to be valid (true) or invalid (false).

value Object

Value of FormValidator.

viewMode Boolean

If true the control will be show only displayedValue.

Return type Description
__baseClassInherit(constructor) None

get className from superclass.

hide(elem?) None

Hide a specified element. The hidden element will not be displayed at all.

isEdit() Boolean

Return true if the form that have an edit.

isValid() Boolean

Returns true when text validation succeeded; otherwise, false.

isVisible(elem?) Boolean

Return true if the element is visible, otherwise false.

reset() None

Reset all state and value to default.

show(elem?) None

Display a specified element.

showValidMessage(valid) None

Show error message if valid is true.

submit(callback?errback?options?) Dojo/Deferred

Submit the form. After form submission is done, callback function or errback function are called depending whether form submission is successful or failure.

toggle(elem?) None

Toggle visibility of a specified element.

Description
enter

Fires when the enter key is pressed.

submit

Fires when submit start.

submit-completed

Fires when submit complete.

submit-error

Fires when submit error.

Constructors Detail
new FormValidator(params?srcNodeRef?)

Create a new FormValidator widget.

Parameters:
constants Detail
<String>
ENCTYPE_FORM

"application/x-www-form-urlencoded" used with form.

<String>
ENCTYPE_UPLOAD

"multipart/form-data" used with upload.

Properties Detail
<Object>
_styleAttr

when you want to set style for other node. you can do this by example... _styleAttr:{ style-property:effected-node } this property was effected where this class was inherited and your widget was called by... var widget = new YourWidget({ style:{ style-property:style-value } }); now effected-node in you widget will have style-property = style-value

Default value: {}

<String>
action

Specifies where to send the form data when a form is submitted.

<Boolean>
active

If true, this forces the control to enter the active state and classname 'amos-form-active' will be added.

Default value: false

<Function>
afterSubmit

Specifies the function that want to do after submit.

Sample:
     <!-- declarative -->
             <form data-dojo-type="esrith/amos/form/FormValidator" data-dojo-props="afterSubmit: ${_formAfterSubmit}">
             </form>
     // programetic
             this.frmValidator = new FormValidator({
                 afterSubmit: lang.hitch(this, "_formAfterSubmit")
             }).placeAt(this.domNode);
             this.frmValidator.submit();
     _formAfterSubmit: function (objResponse) {
                 //to receive response after FormValidator send value to server.
             }
<Boolean>
autoFocusOnError

If true, element that error has focus automatically.

Default value: false

<Function>
beforeSubmit

Specifies the function that want to do before submit.

Sample:
     <!-- declarative -->
             <form data-dojo-type="esrith/amos/form/FormValidator" data-dojo-props="beforeSubmit: ${_formBeforeSubmit}">
             </form>
     // programetic
             this.frmValidator = new FormValidator({
                 beforeSubmit: lang.hitch(this, "_formBeforeSubmit")
             }).placeAt(this.domNode);
             this.frmValidator.submit();
     // when call "submit()"
             _formBeforeSubmit: function (objValue) {
                 //to modify value or do something before FormValidator send value to server.
        
                 //and return new value.
                 return objValue;
             }
<Boolean>
busy

If true, this forces the control to enter the busy state and classname 'amos-form-busy' will be added.

Default value: false

<Object[]>
controls

List of control in a form.

<DataStore | Object[] | String>
dataStore

A data store is a repository of a set of data objects.

<Boolean>
disabled

If true, any control's events(except change) are not responding. Its content cannot be edited and is excluded when the form is submitted.

Default value: false

<String>
enctype

Encoding type for the form (use constant).

Default value: ENCTYPE_FORM

<Boolean>
error

If true, this forces the control to enter the error state and classname 'amos-form-error' will be added.

Default value: false

<Boolean>
errorMessageVisible

Can Specifies the error message to hide or show.

Default value: true

<Boolean>
filled

A flag that shows whether a form element is filled in (true) or empty (false).

Default value: false

<String>
invalidMessage

Text of invalidMessage.

Default value: ระบุไม่ถูกต้อง

<String>
label

Label of an element.

<Node>
messageNode

The element that used to display error message.

<String>
method

HTTP method used to submit the form, either "GET" or "POST".

Default value: post

<String>
name

Name of form for scripting.

<Boolean>
readOnly

If true, the control is read-only and cannot be edited. However, its content, if presents, is included in form submission.

Default value: false

<String>
target

Target frame for the document to be opened in.

Default value: _self

<Boolean>
valid

Validity flag that shows whether a form element is validated to be valid (true) or invalid (false).

Default value: true

<Object>
value

Value of FormValidator.

<Boolean>
viewMode

Inherited from _StateMixin but overwritten in esrith/amos/form/FormValidator.js:141

If true the control will be show only displayedValue.

Default value: false

Methods Detail
__baseClassInherit
(
  • constructor
)

get className from superclass.

Parameters
  • <Object> constructor Required
hide
(
  • elem?
)

Hide a specified element. The hidden element will not be displayed at all.

Parameters
  • <Node> elem Optional

    Specified element to be hidden.

<Boolean>
isEdit
()

Return true if the form that have an edit.

<Boolean>
isValid
()

Returns true when text validation succeeded; otherwise, false.

<Boolean>
isVisible
(
  • elem?
)

Return true if the element is visible, otherwise false.

Parameters
  • <Node> elem Optional

    Specified element to be checked. If not specified, domNode of the widget is used instead.

reset
()

Reset all state and value to default.

show
(
  • elem?
)

Display a specified element.

Parameters
  • <Node> elem Optional

    Specified element to be displayed.

showValidMessage
(
  • valid
)

Show error message if valid is true.

Parameters
<Dojo/Deferred>
submit
(
  • callback?
  • errback?
  • options?
)

Submit the form. After form submission is done, callback function or errback function are called depending whether form submission is successful or failure.

Parameters
  • <Function> callback Optional

    called when submit c

  • <Function> errback Optional

    called when submit error.

  • <Object> options Optional

    param of contructor's DataStore.

toggle
(
  • elem?
)

Toggle visibility of a specified element.

Parameters
  • <Node> elem Optional

    Specified element to toggle visibility.

Events Detail
enter

Fires when the enter key is pressed.

Event Payload:
  • <Object> value

    Value of form when enter key pressed.

submit

Fires when submit start.

Event Payload:
submit-completed

Fires when submit complete.

Event Payload:
  • <Object> response

    Response when submit complete.

submit-error

Fires when submit error.

Event Payload:
  • <Object> err

    Error detail when submit error.