-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Hotfix: preload values to exisitng field types, fix fieldOrder #501
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,12 +64,7 @@ const FormBuilder = function(opts, element) { | |
if (customFields) { | ||
$.merge(controls, customFields); | ||
} | ||
controls = h.orderFields(controls); | ||
|
||
// remove disableFields | ||
if (opts.disableFields) { | ||
controls = controls.filter(type => opts.disableFields.indexOf(type) == -1); | ||
} | ||
|
||
// if we support rearranging control order, add classes to support this | ||
if (opts.sortableControls) { | ||
|
@@ -80,8 +75,11 @@ const FormBuilder = function(opts, element) { | |
let $cbUL = $(d.controls); | ||
|
||
// add each control to the interface | ||
let controlIndex = 0; | ||
for (let type of controls) { | ||
let controlList = []; | ||
const allControls = {}; | ||
|
||
for (let i = 0; i < controls.length; i++) { | ||
let type = controls[i]; | ||
// first check if this is a custom control | ||
let custom = controlCustom.lookup(type); | ||
let controlClass; | ||
|
@@ -98,7 +96,7 @@ const FormBuilder = function(opts, element) { | |
} | ||
let icon = custom.icon || controlClass.icon(type); | ||
let label = custom.label || controlClass.label(type); | ||
let iconClassName = !icon ? custom.iconClassName || `icon-${type}` : ''; | ||
let iconClassName = !icon ? custom.iconClassName || `icon-${type.replace(/-[\d]{4}$/, '')}` : ''; | ||
|
||
// if the class has specified a custom icon, inject it into the label | ||
if (icon) { | ||
|
@@ -108,27 +106,37 @@ const FormBuilder = function(opts, element) { | |
// build & insert the new list item to represent this control | ||
let newFieldControl = m('li', | ||
m('span', label), | ||
{className: `${iconClassName} input-control input-control-${controlIndex}`} | ||
{className: `${iconClassName} input-control input-control-${i}`} | ||
); | ||
newFieldControl.dataset.type = type; | ||
d.controls.appendChild(newFieldControl); | ||
|
||
// map for later access | ||
controlIndex++; | ||
controlList.push(type); | ||
allControls[type] = newFieldControl; | ||
} | ||
|
||
if (opts.inputSets.length) { | ||
$('<li/>', {'class': 'fb-separator'}).html('<hr>').appendTo($cbUL); | ||
opts.inputSets.forEach((set, i) => { | ||
set.name = set.name || utils.makeClassName(set.label); | ||
let inputSet = m('li', set.label, { | ||
className: `input-set-control input-set-${i}`, | ||
type: set.name | ||
className: `input-set-control input-set-${i}` | ||
}); | ||
$(inputSet).appendTo($cbUL); | ||
inputSet.dataset.type = set.name; | ||
controlList.push(set.name); | ||
allControls[set.name] = inputSet; | ||
}); | ||
} | ||
|
||
// remove disableFields | ||
if (opts.disableFields) { | ||
controls = controls.filter(type => opts.disableFields.indexOf(type) == -1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should go either before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to orderFields in helpers |
||
} | ||
|
||
// append controls to list | ||
h.orderFields(controlList).forEach(control => { | ||
if (allControls[control]) { | ||
d.controls.appendChild(allControls[control]); | ||
} | ||
}); | ||
|
||
// Sortable fields | ||
$stage.sortable({ | ||
cursor: 'move', | ||
|
@@ -181,8 +189,7 @@ const FormBuilder = function(opts, element) { | |
let processControl = control => { | ||
if (control[0].classList.contains('input-set-control')) { | ||
let inputSets = []; | ||
let inputSet = opts.inputSets.find(set => | ||
(set.name === control[0].getAttribute('type'))); | ||
let inputSet = opts.inputSets.find(set => (set.name === control[0].dataset.type)); | ||
if (inputSet && inputSet.showHeader) { | ||
let header = { | ||
type: 'header', | ||
|
@@ -302,9 +309,7 @@ const FormBuilder = function(opts, element) { | |
// check for a custom type | ||
let custom = controlCustom.lookup(field.type); | ||
if (custom) { | ||
field.label = custom.label; | ||
field.type = custom.type; | ||
field.subtype = custom.subtype; | ||
field = Object.assign({}, custom); | ||
} else { | ||
let controlClass = control.getClass(field.type); | ||
field.label = controlClass.label(field.type); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinchappell is this
icon-${type.replace(/-[\d]{4}$/, '')}
there to handle the custom fields?If so a better way to write this section may be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree on the custom type but since since the custom type key is randomly generated each time, even if there was an icon of say 'autocomplete-2847' those last 4 digits would change on each initialization. The regex removes hyphen and 4 digits which should only be generated by custom fields. If the custom field is actually an extended base type like in the autocomplete example, its possible the autocomplete icon still wants to be used. To make that happen we strip the '-2847' leaving 'icon-autocomplete'. If they don't want the autocomplete icon they can always explicitly define an icon or iconClassName.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I guess either way works. My implementation above removes ignores the '-1234' by just using the original type defined in
opts.fields
. So... would then output
icon-text
for that custom field.Either way should have the same outcome so up to you which you'd prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. We can always change it if it becomes an issue.