apostrophe-schemas
Advanced tools
Comparing version 0.5.40 to 0.5.41
17
index.js
@@ -196,2 +196,19 @@ var async = require('async'); | ||
_.each(schema, function(field) { | ||
if (field.type === 'select') { | ||
_.each(field.choices, function(choice){ | ||
if (choice.showFields) { | ||
if (!_.isArray(choice.showFields)) { | ||
throw new Error('The \'showFields\' property in the choices of a select field needs to be an array.'); | ||
} | ||
_.each(choice.showFields, function(showFieldName){ | ||
if (!_.find(schema, function(schemaField){ return schemaField.name == showFieldName; })) { | ||
console.error('WARNING: The field \'' + showFieldName + '\' does not exist in your schema, but you tried to toggle it\'s display with a select field using showFields. STAAAHHHHPP!'); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
return schema; | ||
@@ -198,0 +215,0 @@ }; |
{ | ||
"version": "0.5.40", | ||
"version": "0.5.41", | ||
"name": "apostrophe-schemas", | ||
@@ -4,0 +4,0 @@ "description": "Schemas for easy editing of properties in Apostrophe objects", |
@@ -11,3 +11,4 @@ function AposSchemas() { | ||
if (i >= schema.length) { | ||
return callback(null); | ||
return afterPopulateFields(callback); | ||
// return callback(null); | ||
} | ||
@@ -41,2 +42,56 @@ var field = schema[i]; | ||
} | ||
function afterPopulateFields(callback) { | ||
// This function actually toggles the things based on data-show-fields of options in select | ||
function toggleHiddenFields($select){ | ||
var $hideFieldOptions = $select.find('option:not(:selected)'); | ||
_.each($hideFieldOptions, function(hideFieldOption){ | ||
var hideFields = $(hideFieldOption).data('show-fields'); | ||
if (hideFields && hideFields.length > 0) { | ||
hideFields = hideFields.split(','); | ||
_.each(hideFields, function(field){ | ||
var $fieldset = self.findFieldset($el, field); | ||
$fieldset.addClass('apos-hidden'); | ||
}); | ||
} | ||
}); | ||
var showFields = $select.find('option:selected').data('show-fields'); | ||
if (showFields && showFields.length > 0) { | ||
showFields = showFields.split(','); | ||
_.each(showFields, function(field){ | ||
var $fieldset = self.findFieldset($el, field); | ||
$fieldset.removeClass('apos-hidden'); | ||
}); | ||
} | ||
} | ||
// loop over any (safe) select we've marked for functionality, do initial toggle, add listener | ||
_.each(schema, function(field) { | ||
if (field.type == 'select') { | ||
var $fieldset = self.findFieldset($el, field.name); | ||
if ($fieldset.hasClass('apos-fieldset-select-show-fields')){ | ||
var $toggleSelect = self.findSafe($fieldset, 'select'); | ||
toggleHiddenFields($toggleSelect); | ||
$toggleSelect.on('change', function(){ | ||
toggleHiddenFields($(this)); | ||
}); | ||
} | ||
} | ||
}) | ||
callback(null); | ||
} | ||
return populateField(0); | ||
@@ -43,0 +98,0 @@ }; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
104021
1410
1