fixed dropdown option value bug
This commit is contained in:
parent
23c53eb365
commit
5635e352c7
|
@ -395,7 +395,7 @@ FormSchema.pre('save', function (next) {
|
|||
|
||||
//Find FormSubmissions that contain field with _id equal to 'deleted_id'
|
||||
FormSubmission.
|
||||
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {_id: deleted_id} } }).
|
||||
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {submissionId: deleted_id} } }).
|
||||
exec(function(err, submissions){
|
||||
if(err) {
|
||||
console.error(err);
|
||||
|
|
|
@ -60,6 +60,13 @@ function BaseFieldSchema(){
|
|||
Schema.apply(this, arguments);
|
||||
|
||||
this.add({
|
||||
isSubmission: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
submissionId: {
|
||||
type: Schema.Types.ObjectId
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
trim: true,
|
||||
|
@ -138,6 +145,7 @@ function BaseFieldSchema(){
|
|||
if(this.fieldType === 'rating' && this.ratingOptions.validShapes.length === 0){
|
||||
this.ratingOptions.validShapes = mongoose.model('RatingOptions').schema.path('shape').enumValues;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
@ -180,11 +188,26 @@ FormFieldSchema.pre('validate', function(next) {
|
|||
}
|
||||
}
|
||||
|
||||
if(error)
|
||||
return next();
|
||||
});
|
||||
|
||||
//Submission fieldValue correction
|
||||
FormFieldSchema.pre('save', function(next) {
|
||||
console.log('pre save');
|
||||
|
||||
console.log(this.isSubmission);
|
||||
console.log(this._id);
|
||||
console.log(this.submissionId);
|
||||
console.log(this.fieldType);
|
||||
|
||||
if(this.isSubmission && this.fieldType === 'dropdown'){
|
||||
this.fieldValue = this.fieldValue.option_value;
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
|
||||
|
||||
var Field = mongoose.model('Field', FormFieldSchema);
|
||||
var RatingOptions = mongoose.model('RatingOptions', RatingFieldSchema);
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ var mongoose = require('mongoose'),
|
|||
FieldSchema = require('./form_field.server.model.js'),
|
||||
OscarSecurity = require('../../scripts/oscarhost/OscarSecurity');
|
||||
|
||||
var FieldSchema = require('./form_field.server.model.js');
|
||||
|
||||
var newDemoTemplate = {
|
||||
address: '880-9650 Velit. St.',
|
||||
city: '',
|
||||
|
@ -41,6 +43,17 @@ var newDemoTemplate = {
|
|||
yearOfBirth: '2015'
|
||||
};
|
||||
|
||||
|
||||
// Setter function for form_fields
|
||||
function formFieldsSetter(form_fields){
|
||||
for(var i=0; i<form_fields.length; i++){
|
||||
form_fields[i].isSubmission = true;
|
||||
form_fields[i].submissionId = form_fields[i]._id;
|
||||
form_fields[i]._id = new mongoose.mongo.ObjectID();
|
||||
}
|
||||
return form_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form Submission Schema
|
||||
*/
|
||||
|
@ -55,9 +68,7 @@ var FormSubmissionSchema = new Schema({
|
|||
required: true
|
||||
},
|
||||
|
||||
form_fields: {
|
||||
type: [Schema.Types.Mixed]
|
||||
},
|
||||
form_fields: [FieldSchema],
|
||||
|
||||
form: {
|
||||
type: Schema.Types.ObjectId,
|
||||
|
@ -99,7 +110,7 @@ var FormSubmissionSchema = new Schema({
|
|||
},
|
||||
|
||||
timeElapsed: {
|
||||
type: Number,
|
||||
type: Number
|
||||
},
|
||||
percentageComplete: {
|
||||
type: Number
|
||||
|
@ -119,6 +130,8 @@ var FormSubmissionSchema = new Schema({
|
|||
|
||||
});
|
||||
|
||||
FormSubmissionSchema.path('form_fields').set(formFieldsSetter);
|
||||
|
||||
FormSubmissionSchema.plugin(mUtilities.timestamp, {
|
||||
createdPath: 'created',
|
||||
modifiedPath: 'lastModified',
|
||||
|
@ -214,7 +227,7 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
], function(err, result) {
|
||||
if(err) return next(err);
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
},
|
||||
"resolutions": {
|
||||
"angular-bootstrap": "^0.14.0",
|
||||
"angular": "1.4.x",
|
||||
"angular": "~1.4.7",
|
||||
"angular-ui-select": "compiled"
|
||||
},
|
||||
"overrides": {
|
||||
|
|
|
@ -170,10 +170,12 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
|
|||
document.querySelectorAll('.ng-invalid.focusOn')[0].focus();
|
||||
};
|
||||
|
||||
$rootScope.goToInvalid = $scope.submitForm = function() {
|
||||
$rootScope.submitForm = $scope.submitForm = function() {
|
||||
var _timeElapsed = TimeCounter.stopClock();
|
||||
$scope.loading = true;
|
||||
|
||||
var form = _.cloneDeep($scope.myform);
|
||||
|
||||
form.timeElapsed = _timeElapsed;
|
||||
|
||||
form.percentageComplete = $filter('formValidity')($scope.myform) / $scope.myform.visible_form_fields.length * 100;
|
||||
|
|
Loading…
Reference in a new issue