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

Add regex to groups #39

Merged
merged 1 commit into from
Oct 10, 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
5 changes: 2 additions & 3 deletions src/js/common/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const utils = {};

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

return filterArray.length ? !str.match(new RegExp(filterArray.join('|'), 'i')) : true;
Expand Down
5 changes: 2 additions & 3 deletions src/js/components/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Controls {
constructor(controlOptions, formID) {
this.formID = formID;

let defaults = {
var defaults = {
sortable: true,
groupOrder: [
'common',
Expand Down Expand Up @@ -258,7 +258,7 @@ export class Controls {

// remove disabled groups
groups = groups.filter(group => {
return !helpers.inArray(group.id, opts.disable.groups);
return utils.match(group.id, opts.disable.groups);
});

// create group config
Expand All @@ -282,7 +282,6 @@ export class Controls {

group.content = elements.filter(field => {
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));

Expand Down