diff --git a/dynamic-forms.js b/dynamic-forms.js index 374604b..722fc36 100644 --- a/dynamic-forms.js +++ b/dynamic-forms.js @@ -301,13 +301,40 @@ angular.module('dynform', []) } // Button elements get their labels from their contents. else if (["button", "legend", "reset", "submit"].indexOf(field.type) > -1) { - newElement.html(field.label); + newElement.html(field.label).addClass("btn"); } - // Everything else should be wrapped in a label tag. + // check box + else if (["checkbox"].indexOf(field.type) > -1) { + + formGroupWrapper = angular.element('
').addClass("checkbox"); + + newElement = formGroupWrapper.append( + angular.element('').text(" " + field.label).append(newElement) + ); + + // Radio group + } else if (["radio"].indexOf(field.type) > -1) { + + newElement = newElement.wrap('').parent(); + + } + // Everything else should be wrapped in a div tag. else { - newElement = newElement.wrap('').parent(); - newElement.prepend(document.createTextNode(field.label + ' ')); + + formGroupWrapper = angular.element('').addClass("form-group"); + + formGroupWrapper.append( + angular.element('').text(field.label) + ); + + if (field.type != "file" && field.type != "range" && field.type != "checklist") { + newElement.addClass('form-control'); + } + + newElement = newElement.wrap(formGroupWrapper).parent(); + } + } // Arbitrary attributes @@ -316,10 +343,10 @@ angular.module('dynform', []) newElement.attr(attr, val); }); } - - // Add the element to the page + this.append(newElement); newElement = null; + } };