Form Widget

Description:
Adding customizable forms to your webpage with a lot of functions.

Quick navigation Examples

Options

Methods

Events

Options

action

This function is an alias for the url method.

enctype

Type:
String
Default value:
false

Sets the enctype attribute of the form element.

Code examples
Initialize the form widget with the enctype option specified, using object in constructor
$A.newForm({enctype: 'multipart/form-data'}).draw();
            
Initialize the form widget with the enctype option specified, using method chaining
$A.newForm().enctype('multipart/form-data').draw();
            

Get or set the enctype option, after initialization
var form = $A.newForm().draw();
//Setter
form.enctype('multipart/form-data'); //returns form

//Getter
console.log(form.enctype()); //returns value of enctype
            

htmls

Type:
Array
Default value:
[]

By using this option you can insert html code on your form.

Code examples
Initialize the form widget with the htmls option specified, using object in constructor
$A.newForm({htmls: ['<div>html content</div>']}).draw();
            
Initialize the form widget with the htmls option specified, using method chaining
$A.newForm().htmls(['<div>html content</div>']).draw();
            

Get or set the htmls option, after initialization
var form = $A.newForm().draw();
//Setter
form.htmls(['<div>html content</div>']); //returns form
/*
    form.htmls($('.element-to-insert')); //adding jQuery elements
*/

//Getter
console.log(form.htmls()); //returns the htmls array
            

inputs

Type:
Array
Default value:
true

The array of inputs added to the form.

Code examples
Initialize the form widget with the inputs option specified, using object in constructor
$A.newForm({inputs: [$A.newInput(), $A.newInput()]}).draw();
            
Initialize the form widget with the inputs option specified, using method chaining
$A.newForm().inputs([$A.newInput(), $A.newInput()]).draw();
            

Get or set the inputs option, after initialization
var form = $A.newForm().draw();
//Setter
form.inputs([$A.newInput(), $A.newInput()]); //returns form

//Getter
console.log(form.inputs()); //returns the inputs array
            

method

Type:
String
Default value:
'POST'

Use this option to set the method of the form element.

Code examples
Initialize the form widget with the method option specified, using object in constructor
$A.newForm({method: 'POST'}).draw();
            
Initialize the form widget with the method option specified, using method chaining
$A.newForm().method('POST').draw();
            

Get or set the method option, after initialization
var form=$A.newForm().draw();
//Setter
form.method('POST'); //returns form

//Getter
console.log(form.method()); //returns value of method
            

target

Type:
jQuery
Default value:
$('body')

If set in constructor, the form will be automatically drawn to the target element.

Code examples
Initialize the form widget with the target option specified, using object in constructor
$A.newForm({taget: $('body')});
            

url

Type:
String
Default value:
document.location.href

The string containing the URL to which the request is sent.

Code examples
Initialize the form widget with the url option specified, using object in constructor
$A.newForm({url: 'google.com'}).draw();
            
Initialize the form widget with the url option specified, using method chaining
$A.newForm().url('google.com').draw();
            

Get or set the url option, after initialization
var form = $A.newForm().draw();
//Setter
form.url('google.com') //returns form

//Getter
console.log(form.url()) //returns value of url
            

Methods

addGroup(obj)

Returns:
Form

Use this method to create groups of elements on your form.

  • obj
    Type: Object
    The object which represents the elements you want to add to the group.
Code examples
$A.newForm().draw().addGroup({
    text: 'More options',
    inputs: [
        {
            label: 'Import file',
            help: "Select a file to upload that contains contact data that you want to import.",
            type: 'file',
            name: 'import-subscribers',
            accept: ['.csv', '.rar', '.zip', '.tar', '.gz']
        },
        {
            label: 'Apple',
            validator: 'notEmpty'
        }
    ]});
            

addGroups(arr)

Returns:
Form

Use this function to add multiple groups to your form at once.

  • arr
    Type: Array
    The array of object to be added as groups.
Code examples
$A.newForm().draw().addGroups([
    {
        text: 'Group 1',
        inputs: [
            {
                label: 'Import file',
                help: "Select a file to upload that contains contact data that you want to import.",
                type: 'file',
                name: 'import-subscribers',
                accept: ['.csv', '.rar', '.zip', '.tar', '.gz']
            },
            {
                label: 'Apple',
                validator: 'notEmpty'
            }
        ]
    },
    {
        text: 'Group 2',
        inputs: [
            {
                label: $A.translate('Stuff')
            }
        ]
    }]);
            

addHtml(html)

Returns:
Form

Use this method to add html code to your form.

  • html
    Type: String | jQuery
    The element which will be inserted.
Code examples
var form = $A.newForm().draw();
form.addHtml(['<div>html content</div>']); //returns form
form.addHtml($('.elements-to-insert')); //adding jQuery elements
            

addInput(obj)

Returns:
Form

Use this method ta add an input to your form.

  • obj
    Type: Input
    The input you want to add to the form.
Code examples
$A.newForm().addInput($A.newInput()).draw();
            

addInput(arr)

Returns:
Form

Use this method ta add multiple inputs to your form.

  • arr
    Type: Array
    The array of inputs you want to add to your form.
Code examples
$A.newForm().addInputs([$A.newInput(),$A.newInput()]).draw();
            

addSubTitle(str)

Returns:
Form

Use this method to add a subtitle to your form.
Subtitles will be displayed in new rows.

  • str
    Type: String
    The text of the subtitle.
Code examples
$A.newForm().addSubTitle('Title').draw();
            

break

Returns:
Form

Use this method to break line in your form.
Tehnically, a <br> tag will be appended to the widget's html.

Code examples
 //regardless the newRow: false attribute of the inputs, they'll be shown in new lines
$A.newForm().addInput({newRow: false}).break().addInput({newRow: false}).draw();
            

draw($target)

Returns:
Form

Invoke this function to draw the widget after initialization on the target element.
Invoking without parameter sets $('body') as target.

Code examples
Simple way without parameter:
$A.newForm().addInput().draw()          
            
With jQuery element parameter
var container = $('<div id="form-container"></div>').css({height: '200px', margin: '20px 10px', border:'2px solid #FF0000', position:'relative'}).appendTo('body')
var form = $A.newForm();
form.addInput(); 
form.draw(container);          
            

hide()

Returns:
Form

Invoke this function to hide the widget.

Code examples
var form = $A.newForm().draw();
form.addInput();
setTimeout(function (){
    form.hide();
},1000);
            

json

Returns:
String

Use this method to JSON stringify your from.

Code examples
var form = $A.newForm({
        inputs: [$A.newInput({label: 'Name:', value: 'John'})]
    }).draw();
console.log(form.json());
            

object

Returns:
Object

Use this method to serializy the form.

Code examples
var form = $A.newForm({
        inputs: [$A.newInput({label: 'Name:', value: 'John'})]
    }).draw();
console.log(form.object());
            

removeGroup(id)

Use this method to remove a group from your form.

  • id
    Type: String
    The id of the html element representing the group.
Code examples
Give some examples here!
            

removeHtml(id)

Use this method to remove a html from your form.

  • id
    Type: String
    The id of the html element.
Code examples
var form = $A.newForm().addHtml('content').draw();
var id = form.htmls()[0].attr('id');
setTimeout(function(){
    form.removeHtml(id);
},1000);
            

removeInput(obj)

Use this method to remove an input from the form.

  • obj
    Type: Object | String
    The input object you want to remove, or its id.
Code examples
var form = $A.newForm().draw();
var input = $A.newInput().draw();
form.addInput(input);
setTimeout(function (){
    form.removeInput(input);
    }, 1000);
            

removeSubTitle(obj)

Use this to remove a subtitle from your form.

  • obj
    Type: Object | String
    The subtitle you want to remove, or its id.
Code examples
var form = $A.newForm().draw();
form.addSubTitle('title');
setTimeout(function (){
    form.removeSubTitle($($('.automizy-form-subtitle')[0]).attr('id'));
    }, 1000);
            

show()

Returns:
Form

Invoke this function to show the widget.

Code examples
var form = $A.newForm().draw().hide();
form.addInput();
setTimeout(function(){
    form.show();
},1000);          
            

submit

Use this method to submit the form.

Code examples
var form = $A.newInput().draw().submit();
        

validate

Use this method to run the validation process on all inputs in the form.

Code examples
var form = $A.newInput().validator('email').draw().validate();
        

Events

Examples

A simple module


            

Demo: