Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Disable Controls Add floobits files, allow array or string and regex in controls.disable/elements #36

Merged
merged 1 commit into from
Oct 9, 2016
Merged
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
3 changes: 3 additions & 0 deletions .floo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"url": "https://floobits.com/kevinchappell/formeo"
}
10 changes: 10 additions & 0 deletions .flooignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#*
*.o
*.pyc
*~
extern/
node_modules/
tmp
vendor/
dist/
demo/
2,546 changes: 2,539 additions & 7 deletions dist/formeo.min.css

Large diffs are not rendered by default.

12,022 changes: 11,998 additions & 24 deletions dist/formeo.min.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/js/common/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const utils = {};


utils.match = (str, filter) => {
let match = false,
matchOperatorsRe = /[|\\{}()[\]^$+?.]/g,
filterArray = (typeof filter === 'string') ? [filter] : filter;
filterArray = filterArray.map((filterStr) => {
return filterStr === '*' ? '' : filterStr.replace(matchOperatorsRe, '\\$&');
});

if (filterArray.length) {
match = !str.match(new RegExp(filterArray.join('|'), 'i'));
}

return match;
};

export default utils;
14 changes: 8 additions & 6 deletions src/js/components/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import i18n from 'mi18n';
import { data, dataMap, registeredFields } from '../common/data';
import helpers from '../common/helpers';
import events from '../common/events';
import actions from '../common/actions';
import utils from '../common/utils';
import DOM from '../common/dom';
import Panels from './panels';
import Row from './row';
Expand Down Expand Up @@ -108,7 +108,7 @@ export class Controls {
},
options: [1, 2, 3, 4].map(i => {
return {
label: i18n.get('labelCount', { label: i18n.get('option'), count: i }),
label: i18n.get('labelCount', {label: i18n.get('option'), count: i}),
value: 'option-' + i,
selected: false
};
Expand Down Expand Up @@ -143,7 +143,7 @@ export class Controls {
id: 'checkbox'
},
options: [{
label: i18n.get('labelCount', { label: i18n.get('checkbox'), count: 1 }),
label: i18n.get('labelCount', {label: i18n.get('checkbox'), count: 1}),
value: 'checkbox-1',
selected: true
}]
Expand All @@ -163,7 +163,7 @@ export class Controls {
},
options: [1, 2, 3].map(i => {
return {
label: i18n.get('labelCount', { label: i18n.get('radio'), count: i }),
label: i18n.get('labelCount', {label: i18n.get('radio'), count: i}),
value: 'radio-' + i,
selected: false
};
Expand Down Expand Up @@ -281,7 +281,9 @@ export class Controls {
}

group.content = elements.filter(field => {
return (field.meta.group === groups[i].id && !helpers.inArray(field.meta.id, opts.disable.elements));
let match = utils.match(field.meta.id, opts.disable.elements);

return (field.meta.group === groups[i].id && match);
}).map(field => _this.prepElement.call(this, field));

return group;
Expand Down Expand Up @@ -431,7 +433,7 @@ export class Controls {

let groupedFields = this.groupElements();
let formActions = this.formActions();
let controlPanels = new Panels({ panels: groupedFields, type: 'controls' });
let controlPanels = new Panels({panels: groupedFields, type: 'controls'});
let groupsWrap = dom.create({
tag: 'div',
className: 'control-groups panels-wrap panel-count-' + groupedFields.length,
Expand Down