Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Revert 38f1553..2839f68
This rolls back to commit 38f1553.
  • Loading branch information
jbsaff committed Apr 28, 2015
commit dac6d83a9faf35fd676c9b3a0e8647b8c7a9fac6
9 changes: 0 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ General options most field types can handle:
labelHtmlClass: "street" // CSS Class(es) to be added to the label of the field (or similar)
copyValueTo: ["address.street"], // Copy values to these schema keys.
condition: "person.age < 18" // Show or hide field depending on an angular expression
destroyStrategy: '' // Update the model when the field is destoyed, e.g. when condition is not longer satisfied.
}
```

Expand Down Expand Up @@ -824,14 +823,6 @@ function FormCtrl($scope) {
Note that arrays inside arrays won't work with conditions.


### destroyStrategy
By default, when a field is removed from the DOM and the $destroy event is broadcast, the schema-validate directive
will update the model to set the field value to undefined. This can be overridden by setting the destroyStrategy
on a field to one of null, empty string (""), undefined, or "retain". Any other value will be ignored and the default
behavior will apply. The empty string option only applies to fields that have a type of string; using the empty string
with other field types will just be set to the default destroyStrategy. If you'd like to set the destroyStrategy for
an entire form, add it to the formDefaults in the [globalOptions](#global-options)



Specific options and types
Expand Down
67 changes: 2 additions & 65 deletions src/directives/schema-validate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSelect', 'sfUnselect',
function(sfValidator, sfSelect, sfUnselect) {

angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSelect', function(sfValidator, sfSelect) {
return {
restrict: 'A',
scope: false,
Expand All @@ -10,6 +8,7 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {


// We need the ngModelController on several places,
// most notably for errors.
// So we emit it up to the decorator directive so it can put it on scope.
Expand Down Expand Up @@ -102,68 +101,6 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele

});


var DEFAULT_DESTROY_STRATEGY;
if (scope.options && scope.options.formDefaults) {
var formDefaultDestroyStrategy = scope.options.formDefaults.destroyStrategy;
var isValidFormDefaultDestroyStrategy = (formDefaultDestroyStrategy === undefined ||
formDefaultDestroyStrategy === '' ||
formDefaultDestroyStrategy === null ||
formDefaultDestroyStrategy === 'retain');
if (isValidFormDefaultDestroyStrategy) {
DEFAULT_DESTROY_STRATEGY = formDefaultDestroyStrategy;
}
else {
console.warn('Unrecognized formDefaults.destroyStrategy: \'%s\'. Used undefined instead.',
formDefaultDestroyStrategy);
DEFAULT_DESTROY_STRATEGY = undefined;
}
}

// Clean up the model when the corresponding form field is $destroy-ed.
// Default behavior can be supplied as a formDefault, and behavior can be overridden in the form definition.
scope.$on('$destroy', function() {
var form = getForm();
var destroyStrategy = form.destroyStrategy; // Either set in form definition, or as part of formDefaults.
var schemaType = getSchemaType();

if (destroyStrategy && destroyStrategy !== 'retain' ) {
// Don't recognize the strategy, so give a warning.
console.warn('Unrecognized destroyStrategy: \'%s\'. Used default instead.', destroyStrategy);
destroyStrategy = DEFAULT_DESTROY_STRATEGY;
}
else if (schemaType !== 'string' && destroyStrategy === '') {
// Only 'string' type fields can have an empty string value as a valid option.
console.warn('Attempted to use empty string destroyStrategy on non-string form type. Used default instead.');
destroyStrategy = DEFAULT_DESTROY_STRATEGY;
}

if (destroyStrategy === 'retain') {
return; // Valid option to avoid destroying data in the model.
}

destroyUsingStrategy(destroyStrategy);

function destroyUsingStrategy(strategy) {
var strategyIsDefined = (strategy === null || strategy === '' || typeof strategy == undefined);
if (!strategyIsDefined){
strategy = DEFAULT_DESTROY_STRATEGY;
}
sfUnselect(scope.form.key, scope.model, strategy);
}

function getSchemaType() {
if (form.schema) {
schemaType = form.schema.type;
}
else {
schemaType = null;
}
}
});



scope.schemaError = function() {
return error;
};
Expand Down
83 changes: 0 additions & 83 deletions src/services/unselect.js

This file was deleted.