Skip to content

Commit

Permalink
feat(column): add bootstrap grid/column support
Browse files Browse the repository at this point in the history
bootstrap grid/column support (#859)
bs grid support

Authored-By: Jojoshua <Jojoshua@gmail.com>
  • Loading branch information
Jojoshua authored and kevinchappell committed Nov 15, 2018
1 parent 5054335 commit e9cc23a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/js/form-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,30 @@ class FormRender {
className: 'rendered-form',
})
this.appendChild(renderedFormWrap)

fields.forEach(field => {
renderedFormWrap.appendChild(field)
field.dispatchEvent(events.fieldRendered)
// Determine if rows are being used. If so, create the row and append to its row-{group}
// If the fields have row-, create & append to the appropriate row
const [ rowGroup ] = field.className.match(/row-([^\s]+)/)
if(rowGroup){
const rowID = this.id ? `${this.id}-row-${rowGroup}` : `row-${rowGroup}`;

// Check if this rowID is created yet or not.
let rowGroupNode = document.getElementById(rowID);
if(!rowGroupNode){
rowGroupNode = utils.markup('div', null, { id: rowID, className: 'row form-inline' });
renderedFormWrap.appendChild(rowGroupNode)
}
rowGroupNode.appendChild(field);
}
else{
// Append without row
renderedFormWrap.appendChild(field)
}

field.dispatchEvent(events.fieldRendered)
})

}
}

Expand Down
17 changes: 16 additions & 1 deletion src/js/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ export default class layout {
}

// wrap the output in a form-group div & return
const className = data.id ? `fb-${data.type} form-group field-${data.id}` : ''
let className = data.id ? `fb-${data.type} form-group field-${data.id}` : ''

// Lift any col- and row- type class to the form-group wrapper. The row- class denotes the row group it should go to
if(data.className){
const classes = data.className.split(' ').filter(className => (/^col-(xs|sm|md|lg)-([^\s]+)/.test(className) || className.startsWith('row-')));
if(classes && classes.length > 0){
className += ` ${classes.join(' ')}`;

// Now that the col- types were lifted, remove from the actual input field
for (let index = 0; index < classes.length; index++) {
const element = classes[index];
field.classList.remove(element)
}
}
}

return this.markup('div', [label, field], {
className: className,
})
Expand Down

0 comments on commit e9cc23a

Please sign in to comment.