Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

morebits: allow multiple elements in a subgroup

* Subgroup styling moved out to morebits.css
* Make subgroup IDs unique (except for 'option' elements; need to fix
this)
* Removing the attribute name="id" on every QuickForm
  • Loading branch information...
commit d385c289b6de86a30f0b9270c76960bea2a060a4 1 parent e700ec8
@atlight atlight authored
Showing with 33 additions and 10 deletions.
  1. +6 −0 morebits.css
  2. +27 −10 morebits.js
View
6 morebits.css
@@ -90,6 +90,12 @@ form.quickform span.quickformDescription
font-style: italic;
}
+form.quickform .quickformSubgroup
+{
+ margin-bottom: .5em;
+ margin-left: 3em;
+}
+
form.quickform .tooltipButtonContainer
{
position: relative;
View
37 morebits.js
@@ -141,10 +141,12 @@ Morebits.quickForm.element.prototype.append = function QuickFormElementAppend( d
return child;
};
-Morebits.quickForm.element.prototype.render = function QuickFormElementRender() {
- var currentNode = this.compute( this.data );
+// This should be called without parameters: form.render()
+Morebits.quickForm.element.prototype.render = function QuickFormElementRender( internal_subgroup_id ) {
+ var currentNode = this.compute( this.data, internal_subgroup_id );
for( var i = 0; i < this.childs.length; ++i ) {
+ // do not pass internal_subgroup_id to recursive calls
currentNode[1].appendChild( this.childs[i].render() );
}
return currentNode[0];
@@ -164,7 +166,6 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
switch( data.type ) {
case 'form':
node = document.createElement( 'form' );
- node.setAttribute( 'name', 'id' );
node.className = "quickform";
node.setAttribute( 'action', 'javascript:void(0);');
if( data.event ) {
@@ -289,14 +290,26 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
}
var event;
if( current.subgroup ) {
- var tmpgroup = $.extend({}, current.subgroup);
- if( ! tmpgroup.type ) {
- tmpgroup.type = data.type;
+ var tmpgroup = current.subgroup; // $.extend({}, current.subgroup); really needed?
+
+ if( ! $.isArray( tmpgroup ) ) {
+ tmpgroup = [ tmpgroup ];
}
- tmpgroup.name = (current.name || data.name) + '.' + tmpgroup.name;
- var subgroup = this.compute( tmpgroup, cur_id )[0];
- subgroup.style.marginLeft = '3em';
+ var subgroupRaw = new Morebits.quickForm.element({
+ type: 'div',
+ id: id + '_' + i + '_subgroup'
+ });
+ $.each( tmpgroup, function( idx, el ) {
+ if( ! el.type ) {
+ el.type = data.type;
+ }
+ el.name = (current.name || data.name) + '.' + el.name;
+ subgroupRaw.append( el );
+ } );
+
+ var subgroup = subgroupRaw.render( cur_id );
+ subgroup.className = "quickformSubgroup";
subnode.subgroup = subgroup;
subnode.shown = false;
@@ -335,6 +348,7 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
break;
case 'input':
node = document.createElement( 'div' );
+ node.setAttribute( 'id', 'div_' + id );
if( data.label ) {
label = node.appendChild( document.createElement( 'label' ) );
@@ -347,6 +361,7 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
subnode.setAttribute( 'value', data.value );
}
subnode.setAttribute( 'name', data.name );
+ subnode.setAttribute( 'id', id );
subnode.setAttribute( 'type', 'text' );
if( data.size ) {
subnode.setAttribute( 'size', data.size );
@@ -525,10 +540,12 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
break;
case 'textarea':
node = document.createElement( 'div' );
+ node.setAttribute( 'id', 'div_' + id );
if( data.label ) {
label = node.appendChild( document.createElement( 'h5' ) );
label.appendChild( document.createTextNode( data.label ) );
- label.setAttribute( 'for', id );
+ // TODO need to nest a <label> tag in here without creating extra vertical space
+ //label.setAttribute( 'for', id );
}
subnode = node.appendChild( document.createElement( 'textarea' ) );
subnode.setAttribute( 'name', data.name );
Please sign in to comment.
Something went wrong with that request. Please try again.