mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-01-25 14:43:00 +00:00
added validation to exercise creation page
This commit is contained in:
@@ -1,73 +1,57 @@
|
||||
$(document).ready(function() {
|
||||
////Validation
|
||||
var name = new LiveValidation('name');
|
||||
name.add( Validate.Format, { pattern: /^\s*[a-zA-Z0-9,\s]+\s*$/ } );
|
||||
name.add( Validate.Length, { minimum: 3, maximum: 12 , failureMessage: "Please enter a valid name" } );
|
||||
name.add( Validate.Presence );
|
||||
$("#newexercise").validate({
|
||||
rules: {
|
||||
name: {
|
||||
required: true,
|
||||
remote: {
|
||||
cache:false,
|
||||
async:false,
|
||||
dataType: 'json',
|
||||
url: "/admin/exercises",
|
||||
type: "post",
|
||||
data: {
|
||||
name: function() {
|
||||
return $("#name").val();
|
||||
}
|
||||
},
|
||||
dataFilter: function(data) {
|
||||
return (JSON.parse(data).name);
|
||||
}
|
||||
}
|
||||
},
|
||||
difficulty: {
|
||||
required: true,
|
||||
digits: true,
|
||||
range: [1, 10]
|
||||
},
|
||||
description: {
|
||||
required: true,
|
||||
maxlength: 24
|
||||
},
|
||||
type: {
|
||||
notEqual: "notselected",
|
||||
required: true
|
||||
}
|
||||
},
|
||||
messages: {
|
||||
name: {
|
||||
required: "Please enter an exercise name",
|
||||
remote: "Name already taken"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var type = new LiveValidation('type');
|
||||
type.add( Validate.Exclusion, { within: ['notselected', 'Select One'], failureMessage: "Please select an entry from the list" } );
|
||||
type.add( Validate.Presence );
|
||||
var difficulty = new LiveValidation('difficulty');
|
||||
difficulty.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
difficulty.add( Validate.Presence );
|
||||
var description = new LiveValidation('description');
|
||||
description.add( Validate.Format, { pattern: /^\s*[a-zA-Z0-9,\s]+\s*$/ } );
|
||||
description.add( Validate.Presence );
|
||||
var musclearray0 = new LiveValidation('musclearray[0]');
|
||||
musclearray0.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray0.add( Validate.Presence );
|
||||
var musclearray1 = new LiveValidation('musclearray[1]');
|
||||
musclearray1.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray1.add( Validate.Presence );
|
||||
var musclearray2 = new LiveValidation('musclearray[2]');
|
||||
musclearray2.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray2.add( Validate.Presence );
|
||||
var musclearray3 = new LiveValidation('musclearray[3]');
|
||||
musclearray3.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray3.add( Validate.Presence );
|
||||
var musclearray4 = new LiveValidation('musclearray[4]');
|
||||
musclearray4.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray4.add( Validate.Presence );
|
||||
var musclearray5 = new LiveValidation('musclearray[5]');
|
||||
musclearray5.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray5.add( Validate.Presence );
|
||||
var musclearray6 = new LiveValidation('musclearray[6]');
|
||||
musclearray6.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray6.add( Validate.Presence );
|
||||
var musclearray7 = new LiveValidation('musclearray[7]');
|
||||
musclearray7.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray7.add( Validate.Presence );
|
||||
var musclearray8 = new LiveValidation('musclearray[8]');
|
||||
musclearray8.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray8.add( Validate.Presence );
|
||||
var musclearray9 = new LiveValidation('musclearray[9]');
|
||||
musclearray9.add( Validate.Numericality, { minimum: 1, maximum: 10, onlyInteger: true, failureMessage: "Must be a number between 1 and 10" });
|
||||
musclearray9.add( Validate.Presence );
|
||||
|
||||
// Pass a function that checks if a number is divisible by one that you pass it in args object
|
||||
// In this case, 5 is passed, so should return true and validation will pass
|
||||
//Validate.Custom( 55, { against: function(value,args){ return !(value % args.divisibleBy) }, args: {divisibleBy: 5} } );
|
||||
|
||||
// $.ajax({
|
||||
// type: 'get',
|
||||
// url: '/admin/exercises/',
|
||||
// data: { name: 'Cheddar'}
|
||||
// });
|
||||
|
||||
|
||||
// $.getJSON('admin/exercise', function(data) {
|
||||
// var items = [];
|
||||
|
||||
// $.each(data, function(key, val) {
|
||||
// items.push('<li id="' + key + '">' + val + '</li>');
|
||||
// });
|
||||
|
||||
// $('<ul/>', {
|
||||
// 'class': 'my-new-list',
|
||||
// html: items.join('')
|
||||
// }).appendTo('body');
|
||||
// });
|
||||
$(".musclearray").each(function(){
|
||||
$(this).rules("add", {
|
||||
required: true,
|
||||
digits: true,
|
||||
range: [1, 10],
|
||||
messages: {
|
||||
required: "Muscle Array values must be betwen 1 and 10"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -65,5 +65,12 @@ $(document).ready(function() {
|
||||
|
||||
|
||||
|
||||
|
||||
jQuery.validator.addMethod("notEqual", function(value, element, param) {
|
||||
return this.optional(element) || value != param;
|
||||
},"Please select a value");
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user