added validation for rating steps
This commit is contained in:
parent
6131f7de94
commit
7f8099f4a1
|
@ -26,7 +26,9 @@ var FieldOptionSchema = new Schema({
|
||||||
|
|
||||||
var RatingFieldSchema = new Schema({
|
var RatingFieldSchema = new Schema({
|
||||||
steps: {
|
steps: {
|
||||||
type: Number
|
type: Number,
|
||||||
|
min: 1,
|
||||||
|
max: 10
|
||||||
},
|
},
|
||||||
shape: {
|
shape: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -166,8 +168,6 @@ FormFieldSchema.pre('validate', function(next) {
|
||||||
//Checking that the fieldValue is between 0 and ratingOptions.steps
|
//Checking that the fieldValue is between 0 and ratingOptions.steps
|
||||||
if(this.fieldValue+0 > this.ratingOptions.steps || this.fieldValue+0 < 0){
|
if(this.fieldValue+0 > this.ratingOptions.steps || this.fieldValue+0 < 0){
|
||||||
this.fieldValue = 1;
|
this.fieldValue = 1;
|
||||||
//error.errors.fieldValue = mongoose.Error.ValidatorError({path:'fieldValue', message: 'fieldValue is not within proper range for rating field.', type: 'notvalid', value: this.fieldValue});
|
|
||||||
//return(next(error));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
|
||||||
'option_value' : 'Option 0'
|
'option_value' : 'Option 0'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(newField);
|
|
||||||
|
|
||||||
// put newField into fields array
|
// put newField into fields array
|
||||||
if(modifyForm){
|
if(modifyForm){
|
||||||
$scope.myform.form_fields.push(newField);
|
$scope.myform.form_fields.push(newField);
|
||||||
|
|
|
@ -46,7 +46,7 @@ angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$root
|
||||||
forms: '='
|
forms: '='
|
||||||
},
|
},
|
||||||
link: function(scope, element) {
|
link: function(scope, element) {
|
||||||
|
|
||||||
$rootScope.chooseDefaultOption = scope.chooseDefaultOption = function(type) {
|
$rootScope.chooseDefaultOption = scope.chooseDefaultOption = function(type) {
|
||||||
if(type === 'yes_no'){
|
if(type === 'yes_no'){
|
||||||
scope.field.fieldValue = 'true';
|
scope.field.fieldValue = 'true';
|
||||||
|
@ -99,16 +99,6 @@ angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$root
|
||||||
}
|
}
|
||||||
var template = getTemplateUrl(fieldType);
|
var template = getTemplateUrl(fieldType);
|
||||||
element.html(template).show();
|
element.html(template).show();
|
||||||
|
|
||||||
if(scope.field.fieldType === 'rating'){
|
|
||||||
//while($filter('toFaIcon')('Heart', false) == '-') {
|
|
||||||
|
|
||||||
//angular.element('input-stars').attr('icon-full', $filter('toFaIcon')('Heart', false));
|
|
||||||
//angular.element('input-stars').attr('icon-empty', $filter('toFaIcon')('Heart', true));
|
|
||||||
|
|
||||||
//console.log($filter('toFaIcon')('Heart', false));
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
var output = $compile(element.contents())(scope);
|
var output = $compile(element.contents())(scope);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
// 'use strict';
|
|
||||||
//
|
|
||||||
// angular.module('forms').filter('toFaIcon', ['FontAwesomeIcons', '$timeout', function(FontAwesomeIcons, $timeout) {
|
|
||||||
// var data = null, // DATA RECEIVED ASYNCHRONOUSLY AND CACHED HERE
|
|
||||||
// serviceInvoked = false;
|
|
||||||
//
|
|
||||||
// var getRatingShape = function (fieldType, iconData) {
|
|
||||||
// var iconObj = {
|
|
||||||
// full: "",
|
|
||||||
// empty: ""
|
|
||||||
// };
|
|
||||||
// var supported_fields = [
|
|
||||||
// 'Heart',
|
|
||||||
// 'Star',
|
|
||||||
// 'thumbs-up',
|
|
||||||
// 'thumbs-down',
|
|
||||||
// 'Circle',
|
|
||||||
// 'Square',
|
|
||||||
// 'Check Circle',
|
|
||||||
// 'Smile Outlined',
|
|
||||||
// 'Hourglass',
|
|
||||||
// 'bell',
|
|
||||||
// 'Paper Plane',
|
|
||||||
// 'Comment',
|
|
||||||
// 'Trash'
|
|
||||||
// ];
|
|
||||||
// if (__indexOf.call(iconData.iconList, fieldType) >= 0) {
|
|
||||||
//
|
|
||||||
// iconObj.full = "fa-"+iconData.iconMap[fieldType];
|
|
||||||
// iconObj.empty = "fa-"+iconData.iconMap[fieldType]+"-o";
|
|
||||||
// if(fieldType == "thumbs-up" || fieldType == "thumbs-down"){
|
|
||||||
// iconObj.empty = "fa-"+iconData.iconMap[fieldType].split("-")[0]+"-o-"+iconData.iconMap[fieldType].split("-")[1];
|
|
||||||
// }else if(fieldType == "Smile Outlined"){
|
|
||||||
// iconObj.empty = "fa-frown-o";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return iconObj;
|
|
||||||
// } else {
|
|
||||||
// throw new Error("Error no shape of type: " + fieldType + " for rating input");
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// var realFilter = function initialFilter(shapeType, isEmpty) {
|
|
||||||
// console.log('oldFilter');
|
|
||||||
// if(isEmpty) return "fa-star-o"; // PLACEHOLDER
|
|
||||||
// else return "fa-star";
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// // function filterStub(shapeType, isEmpty){
|
|
||||||
// // if( data === null ) {
|
|
||||||
// // if (!serviceInvoked) {
|
|
||||||
// // serviceInvoked = true;
|
|
||||||
// //$timeout(function () {
|
|
||||||
// FontAwesomeIcons.get().then(function (result) {
|
|
||||||
// data = result;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// realFilter = function newFilter(shapeType, isEmpty) {
|
|
||||||
// console.log('newFilter');
|
|
||||||
// var faData = getRatingShape(shapeType, data);
|
|
||||||
// if (isEmpty) return faData.empty;
|
|
||||||
// return faData.full;
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// }, function (err) {
|
|
||||||
// throw new Error("toShapeIcon Error: " + err.message || err);
|
|
||||||
// });
|
|
||||||
// /*realFilter = function newFilter(shapeType, isEmpty) {
|
|
||||||
// console.log('newFilter');
|
|
||||||
// if(isEmpty) return "fa-heart-o"; // PLACEHOLDER
|
|
||||||
// else return "fa-heart";
|
|
||||||
// }*/
|
|
||||||
// //}, 1000);
|
|
||||||
// // }
|
|
||||||
// // return "-";
|
|
||||||
// // //if(isEmpty) return "fa-star-o"; // PLACEHOLDER
|
|
||||||
// // //else return "fa-star";
|
|
||||||
// // } else return realFilter(shapeType, isEmpty);
|
|
||||||
// // }
|
|
||||||
// // filterStub.$stateful = true;
|
|
||||||
// // return filterStub;
|
|
||||||
//
|
|
||||||
// function tempFilter(shapeType, isEmpty) {
|
|
||||||
// return realFilter(shapeType, isEmpty);
|
|
||||||
// }
|
|
||||||
// tempFilter.$stateful = true;
|
|
||||||
//
|
|
||||||
// return tempFilter;
|
|
||||||
//
|
|
||||||
// }]);
|
|
|
@ -179,14 +179,13 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$scope.submitPromise = $http.post('/forms/' + $scope.myform._id, form)
|
$scope.submitPromise = $http.post('/forms/' + $scope.myform._id, form)
|
||||||
.success(function (data, status, headers) {
|
.success(function (data, status, headers) {
|
||||||
//console.log('form submitted successfully');
|
|
||||||
|
|
||||||
$scope.myform.submitted = true;
|
$scope.myform.submitted = true;
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
})
|
})
|
||||||
.error(function (error) {
|
.error(function (error) {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
//console.log(error);
|
console.error(error);
|
||||||
$scope.error = error.message;
|
$scope.error = error.message;
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
// 'use strict';
|
|
||||||
//
|
|
||||||
// //Font-awesome-icon service used for fetching and mapping icon class names
|
|
||||||
// angular.module('forms').service('FontAwesomeIcons', ['$http', '$q',
|
|
||||||
// function($http, $q){
|
|
||||||
//
|
|
||||||
// var iconData = {};
|
|
||||||
// this.get = function(callback){
|
|
||||||
//
|
|
||||||
// var deferred = $q.defer();
|
|
||||||
//
|
|
||||||
// //Fetch icon list from font-awesome repo
|
|
||||||
// $http.get('https://raw.githubusercontent.com/FortAwesome/Font-Awesome/gh-pages/icons.yml').then(function (response) {
|
|
||||||
// var parsedData = jsyaml.load(response.data);
|
|
||||||
//
|
|
||||||
// var parsedIconData = {
|
|
||||||
// iconMap: {},
|
|
||||||
// iconList: [],
|
|
||||||
// iconCategoryList: []
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// var icons = parsedData.icons;
|
|
||||||
//
|
|
||||||
// for (var i = 0; i < icons.length; i++) {
|
|
||||||
// parsedIconData.iconMap[icons[i].name] = icons[i].id;
|
|
||||||
// parsedIconData.iconList.push(icons[i].name);
|
|
||||||
//
|
|
||||||
// for (var x = 0; x < icons[i].categories.length; x++) {
|
|
||||||
// if (!parsedIconData.iconCategoryList[icons[i].categories[x]]) parsedIconData.iconCategoryList[icons[i].categories[x]] = [];
|
|
||||||
// parsedIconData.iconCategoryList[icons[i].categories[x]].push(icons[i].name);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// deferred.resolve(parsedIconData);
|
|
||||||
// },
|
|
||||||
// //Error Callback Function
|
|
||||||
// function(data){
|
|
||||||
// var error = response.data || "Request failed";
|
|
||||||
// deferred.reject(error);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// return deferred.promise;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// ]);
|
|
|
@ -25,7 +25,6 @@ angular.module('forms').factory('Forms', ['$resource',
|
||||||
transformResponse: function(data, header) {
|
transformResponse: function(data, header) {
|
||||||
var form = angular.fromJson(data);
|
var form = angular.fromJson(data);
|
||||||
|
|
||||||
console.log(form.form_fields);
|
|
||||||
form.visible_form_fields = _.filter(form.form_fields, function(field){
|
form.visible_form_fields = _.filter(form.form_fields, function(field){
|
||||||
return (field.deletePreserved === false);
|
return (field.deletePreserved === false);
|
||||||
});
|
});
|
||||||
|
|
|
@ -249,7 +249,12 @@
|
||||||
<div class="row" ng-if="showRatingOptions(field)">
|
<div class="row" ng-if="showRatingOptions(field)">
|
||||||
<div class="col-md-9 col-sm-9">Number of Steps:</div>
|
<div class="col-md-9 col-sm-9">Number of Steps:</div>
|
||||||
<div class="col-md-3 col-sm-3">
|
<div class="col-md-3 col-sm-3">
|
||||||
<input style="width:100%" type="number" ng-model="field.ratingOptions.steps" name="ratingOptions_steps{{field._id}}" ng-value="{{field.ratingOptions.steps}}" required>
|
<input style="width:100%" type="number"
|
||||||
|
min="1" max="10"
|
||||||
|
ng-model="field.ratingOptions.steps"
|
||||||
|
name="ratingOptions_steps{{field._id}}"
|
||||||
|
ng-value="{{field.ratingOptions.steps}}"
|
||||||
|
required>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div class="col-md-5 col-sm-9">Shape:</div>
|
<div class="col-md-5 col-sm-9">Shape:</div>
|
||||||
|
|
Loading…
Reference in a new issue