Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 37 additions & 36 deletions bootstrap-formform.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,12 @@ var FormForm = (function () {

if ( type == 'select' ) return new ElementSelect( itemData );
else if ( type == 'textarea' ) return new ElementTextarea( itemData );
else if ( type in { 'button':0, 'submit':0, 'reset':0 } ) return new ElementButton( itemData );
else if ( isButton(type) ) return new ElementButton( itemData );
else if ( type == 'static' ) return new ElementStatic( itemData );
else if ( type == 'radiogroup' ) return new ElementRadiogroup( itemData );
else if ( type == 'file' ) return new ElementFile( itemData );
else if ( type == 'hidden' ) return new ElementHidden( itemData );
else if ( type in {
text:0,
password:0,
datetime:0,
'datetime-local':0,
date:0,
month:0,
time:0,
week:0,
number:0,
email:0,
url:0,
search:0,
tel:0,
color:0,
checkbox:0,
radio:0
} ) return new Element( itemData );
else if ( isTextInput(type) ) return new Element( itemData );

if ( ! type ) return new Element( itemData );
else throw new Error( 'unknown type: ' + itemData.type );
Expand All @@ -61,6 +44,7 @@ var FormForm = (function () {
var self = this; // will ECMA 6 finally fix this crap?
var buttons = [];
var btnsAlignRight = '';
var formform = this;

Element.prototype.isHorizontal = this.isHorizontal ? [this.col1, this.col2] : null;

Expand All @@ -70,7 +54,7 @@ var FormForm = (function () {
var item = self.createItem( itemData ).render();

// filter out any buttons on the form root (with added whitespace for proper spacing)
if ( itemData.type == 'submit' || itemData.type == 'button' )
if ( isButton(itemData.type))
{
if ( itemData.position == 'right' ) btnsAlignRight = ' text-right';
buttons.push( item, "\n" );
Expand Down Expand Up @@ -164,6 +148,38 @@ var FormForm = (function () {
}
}

// ---------------------------------

var isTextInput = function(type)
{
return type in {
text:0,
password:0,
datetime:0,
'datetime-local':0,
date:0,
month:0,
time:0,
week:0,
number:0,
email:0,
url:0,
search:0,
tel:0,
color:0,
checkbox:0,
radio:0
};
}

// ---------------------------------

var isButton = function(type)
{
return type in {button:0, reset:0, submit:0, menu:0};
}


// -----------------------------------------------------------------------------
// FormForm Elements
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -331,22 +347,7 @@ var FormForm = (function () {
if ( typeof this.itemData.value != 'undefined' ) this.elem.val( this.itemData.value );

// create (optional) addons and enclosing group
if ( this.itemData.addons && this.elem.attr( 'type' ) in {
text:0,
password:0,
datetime:0,
'datetime-local':0,
date:0,
month:0,
time:0,
week:0,
number:0,
email:0,
url:0,
search:0,
tel:0,
color:0
} ) return this.createAddons();
if ( this.itemData.addons && isTextInput( this.elem.attr( 'type' ) ) ) return this.createAddons();
else return this.createGroup();
}

Expand Down
2 changes: 1 addition & 1 deletion formform_demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
"classes": "btn-primary"
},
{
"type": "button",
"type": "reset",
"label": "Reset",
"classes": "btn-danger"
},
Expand Down