| 23783 |
ashik.ali |
1 |
$().ready(function() {
|
|
|
2 |
$("form#create-item-form input").each(function(){
|
|
|
3 |
$(this).attr('autocomplete', 'off');
|
|
|
4 |
});
|
|
|
5 |
});
|
|
|
6 |
$().ready(function() {
|
|
|
7 |
// validate the comment form when it is submitted
|
|
|
8 |
$('#create-item-form').validate({
|
|
|
9 |
rules:{
|
|
|
10 |
vendor:{
|
|
|
11 |
required:true
|
|
|
12 |
},
|
|
|
13 |
itemBrand:{
|
|
|
14 |
required:true
|
|
|
15 |
},
|
|
|
16 |
description:{
|
|
|
17 |
required:true
|
|
|
18 |
}
|
|
|
19 |
},
|
|
|
20 |
messages:{
|
|
|
21 |
vendor:{
|
|
|
22 |
required:"Please choose vendor"
|
|
|
23 |
},
|
|
|
24 |
itemBrand:{
|
|
|
25 |
required:"Please enter brand"
|
|
|
26 |
},
|
|
|
27 |
description:{
|
|
|
28 |
required: "Please enter description"
|
|
|
29 |
}
|
|
|
30 |
},
|
|
|
31 |
submitHandler: function (form, event) {
|
|
|
32 |
event.preventDefault();
|
|
|
33 |
if(validateItemDetails()){
|
|
|
34 |
alert("Please fix errors");
|
|
|
35 |
return false;
|
|
|
36 |
}
|
|
|
37 |
var json = itemDetailsJson();
|
|
|
38 |
console.log("itemJson = " + json);
|
|
|
39 |
if(confirm("Are you sure you want to create Item!") == true){
|
|
|
40 |
doPostAjaxRequestWithJsonHandler(context+"/createItem", json, function(response){
|
|
|
41 |
$('#main-content').html(response);
|
|
|
42 |
});
|
|
|
43 |
return false; // required to block normal submit since you used ajax
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
});
|
|
|
47 |
|
|
|
48 |
});
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
function validateItemDetails(){
|
|
|
52 |
console.log("validating Item Details...");
|
|
|
53 |
var error = false;
|
|
|
54 |
var vendorId = $("#vendors").val();
|
|
|
55 |
console.log("vendorId = " + vendorId);
|
|
|
56 |
$("#vendor").removeClass("border-highlight");
|
|
|
57 |
if(vendorId == ""){
|
|
|
58 |
alert("Vendor is required");
|
|
|
59 |
$("#vendorId").addClass("border-highlight");
|
|
|
60 |
error = true;
|
|
|
61 |
return error;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
var itemBrand = $("form#create-item-form input[name=itemBrand]").val();
|
|
|
65 |
console.log("itemBrand = " + itemBrand);
|
|
|
66 |
$("#itemBrand").removeClass("border-highlight");
|
|
|
67 |
if(itemBrand == ""){
|
|
|
68 |
alert("Brand is required");
|
|
|
69 |
$("#itemBrand").addClass("border-highlight");
|
|
|
70 |
error = true;
|
|
|
71 |
return error;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
var description = $("form#create-item-form input[name=description]").val();
|
|
|
75 |
console.log("description = " + description);
|
|
|
76 |
$("#description").removeClass("border-highlight");
|
|
|
77 |
if(description == ""){
|
|
|
78 |
alert("Description is required");
|
|
|
79 |
$("#description").addClass("border-highlight");
|
|
|
80 |
error = true;
|
|
|
81 |
return error;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
var typeString = $("#types").val();
|
|
|
85 |
console.log("typeString = " + typeString);
|
|
|
86 |
$("#types").removeClass("border-highlight");
|
|
|
87 |
if(typeString == ""){
|
|
|
88 |
alert("Type is required");
|
|
|
89 |
$("#types").addClass("border-highlight");
|
|
|
90 |
error = true;
|
|
|
91 |
return error;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
var price = $("form#create-item-form input[name=price]").val();
|
|
|
95 |
console.log("price = " + price);
|
|
|
96 |
if (price == ""){
|
|
|
97 |
$("form#create-item-form input[name=price]").val(0);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
console.log("validation vendor error = " + error);
|
|
|
101 |
return error;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
function itemDetailsJson(){
|
|
|
105 |
console.log("itemDetailsJson");
|
|
|
106 |
var itemObject = {};
|
|
|
107 |
itemObject['vendorId'] = $("#vendors").val();
|
|
|
108 |
itemObject['brand'] = $("form#create-item-form input[name=itemBrand]").val();
|
|
|
109 |
itemObject['description'] = $("form#create-item-form input[name=description]").val();
|
|
|
110 |
itemObject['typeString'] = $('#types').val();
|
|
|
111 |
itemObject['price'] = $("form#create-item-form input[name=price]").val();
|
|
|
112 |
return JSON.stringify(itemObject);
|
|
|
113 |
}
|