Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Custom_Validate(element) {
- //Set the current validate to true
- var validate = true;
- //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
- $(element ? element : '[validationgroupname="AllValidators"]').each(function () {
- //Assigns $(this) to a variable
- var $this = $(this);
- //Takes the poroperty tagName and puts it lower case
- switch ($this.prop('tagName').toLowerCase()) {
- case 'input':
- {
- //This will check to see if the textbox has any value and if not it willput validate to false and show the error
- if ($this.val().length == 0) {
- $('#' + $this.data('describeby')).text('Meal Name is Not Valid').show();
- validate = false;
- return;
- }
- //This will check the regex expression for special characters and show the error if there is some found and set validate to false
- else if (!/^[a-zA-Z0-9-/ ]*$/.test($this.val())) {
- $('#' + $this.data('describeby')).text('Meal Name Contains an Invalid Character').show();
- validate = false;
- return;
- }
- //If both properties do not match then it will hide the error
- else {
- $('#' + $this.data('describeby')).hide();
- return;
- }
- }
- case 'select':
- {
- //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
- if ($this.val() == 0) {
- $('#' + $this.data('describeby')).text('Please Choose an Item Category').show();
- validate = false;
- return;
- } else {
- $('#' + $this.data('describeby')).hide();
- return;
- }
- }
- }
- });
- //Return the validate
- return validate;
- }
- function Form_Validate() {
- //When this is called by the onClientClick button it will send a function call to validate all fields and return the update
- var validated = Custom_Validate();
- //If the update is true, then it will continue to send the ajax call
- if (validated) {
- //Make the postData look similar to the meal food view model
- var postData = {
- MealName: $('#ContentPlaceHolder1_EditMealName').val(),
- MealCategoryID: $('#ContentPlaceHolder1_EditCategoryName').val(),
- FoodID: []
- };
- //Search through each of thsese IDS
- $('#editItemDropdownList_0, #editItemDropdownList_1, #editItemDropdownList_2, #editItemDropdownList_3, #editItemDropdownList_4')
- .each(function () {
- //On each ID push the value with aradix of 10
- postData.FoodID.push(parseInt($(this).val(), 10));
- });
- //Send the ajax call through AddMeal.aspx
- $.ajax({
- url: "http://localhost:63591/EditMeal.aspx",
- method: 'POST',
- data: { data: JSON.stringify(postData) }
- });
- }
- //This will return false on all, to avoid a double submissions of viewstate
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement