Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. function Custom_Validate(element) {
  2. //Set the current validate to true
  3. var validate = true;
  4. //Checks to see there is an element attached to it so it can check that only event and not every single one, but if there is not it will check everything due to it thinking it is a form submission
  5. $(element ? element : '[validationgroupname="AllValidators"]').each(function () {
  6. //Assigns $(this) to a variable
  7. var $this = $(this);
  8. //Takes the poroperty tagName and puts it lower case
  9. switch ($this.prop('tagName').toLowerCase()) {
  10. case 'input':
  11. {
  12. //This will check to see if the textbox has any value and if not it willput validate to false and show the error
  13. if ($this.val().length == 0) {
  14. $('#' + $this.data('describeby')).text('Meal Name is Not Valid').show();
  15. validate = false;
  16. return;
  17.  
  18. }
  19. //This will check the regex expression for special characters and show the error if there is some found and set validate to false
  20. else if (!/^[a-zA-Z0-9-/ ]*$/.test($this.val())) {
  21. $('#' + $this.data('describeby')).text('Meal Name Contains an Invalid Character').show();
  22. validate = false;
  23. return;
  24. }
  25. //If both properties do not match then it will hide the error
  26. else {
  27. $('#' + $this.data('describeby')).hide();
  28. return;
  29. }
  30. }
  31. case 'select':
  32. {
  33. //Checks to see if the value is not 0 which is the orginal select statement. If it is it will show the error and set the validate to false
  34. if ($this.val() == 0) {
  35. $('#' + $this.data('describeby')).text('Please Choose an Item Category').show();
  36. validate = false;
  37. return;
  38. } else {
  39. $('#' + $this.data('describeby')).hide();
  40. return;
  41. }
  42. }
  43. }
  44. });
  45. //Return the validate
  46. return validate;
  47. }
  48.  
  49. function Form_Validate() {
  50. //When this is called by the onClientClick button it will send a function call to validate all fields and return the update
  51. var validated = Custom_Validate();
  52. //If the update is true, then it will continue to send the ajax call
  53. if (validated) {
  54. //Make the postData look similar to the meal food view model
  55. var postData = {
  56. MealName: $('#ContentPlaceHolder1_EditMealName').val(),
  57. MealCategoryID: $('#ContentPlaceHolder1_EditCategoryName').val(),
  58. FoodID: []
  59. };
  60. //Search through each of thsese IDS
  61. $('#editItemDropdownList_0, #editItemDropdownList_1, #editItemDropdownList_2, #editItemDropdownList_3, #editItemDropdownList_4')
  62. .each(function () {
  63. //On each ID push the value with aradix of 10
  64. postData.FoodID.push(parseInt($(this).val(), 10));
  65. });
  66. //Send the ajax call through AddMeal.aspx
  67. $.ajax({
  68. url: "http://localhost:63591/EditMeal.aspx",
  69. method: 'POST',
  70. data: { data: JSON.stringify(postData) }
  71. });
  72. }
  73. //This will return false on all, to avoid a double submissions of viewstate
  74. return false;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement