-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
183 lines (168 loc) · 5.15 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* This file show a usage of FormValidtor
*/
let form = document.querySelector('.auth-form');
let formdata = new FormData();
Validator.setMaxdate('#date', 18);
Validator.setPhone('[name="phone"]', true);
Validator.setMaxdate('[name="sO"]', 18);
formdata.append('myformdatakey', 'myformdatavalue');
formdata.append('myformdatakey', 'This is a dublicate of all myformdatakey');
let myCustomRules = {
newRule : {
callback : function(v, e,k,addError){
return v === 'Important value';
},
msg : "New rule validates that your input value should be 'Important value'."
},
customRule : {
callback : function(v,e,k,addError){
console.log(v,e,k,addError);
return v=="Hi";
},
msg : "Your given value should be 'Hi'."
}
}
Validator.extend(myCustomRules);
let validate = {
rules: {
url: 'url:1',
myinput: 'required|min:6|max:12|email',
textarea: { min: 19 },
checkbox: 'accept',
dateTime: [
'date',
{ tillDate: -19 }
],
singleFile: ['required',
{ fileSize: (1024 * 1024) * 3 },//5mb (1024*1024)*5
{
dimension:
{ smallest: [735, 1102], highest: [1000, 1500] }
}
],
zipCode: 'zipCode',
newInput: 'required|min:6',
anInput: [
'required',
{
any_of_rules: [
"zipCode",
"min:9"
]
}],
phone : 'required',
numb: [
{
range: [4, 9]
},
{ numb_space: true }
],
password:
{
any_of: {
password: 'required|password',
conpassword: 'required|same:password',
}
},
field1: {
only_any_of: {
makeInvalidEmpty: true,
// Either field1 should be email or field2 should be numb both can't happen at the same time
fields : {
field1: "required|email",
field2: "required|numb"
},
}
},
// password : 'password',
// conpassword : 'same:password',
inList: [{
inList: ['abc', 'cde', 'fgh']
}],
n: ['required', {
inList: ['abc', 'cde', 'fgh']
}],
json: 'json:1',
ean: 'required|ean',
isbn10: 'required|isbn10',
barcode: 'required|barcode',
upc: 'required|upca',
date : 'required|dateAll',
sdateTime : 'required|dateTime',
myRule : 'customRule',
newRule:'newRule',
customInput : {
notRule : ['zipCode','min:9']
},
t:{tillDate:1},
sO:{
shouldOld:18
},//can do it like this too "shoulOld:18"
customDate: [
'date',
{tillDate:1}
],
customDate1:"dateTime|shouldOld:18"
// {shouldOld:18}
},
errorMsgs: {
myinput: {
required: "This is a custom message for required field",
},
singleFile: {
fileSize: "The file size exceeds max file size which is 3mb."
},
url: {
url_ftp: 'The entered url is not a valid url'
},
anInput_any_of_rules: "This field either needs to be a zip code or contains 9 characters.",
password: {
any_of: "Either the password should be a password or conpassword match with password."
},
conpassword: {
same: "Either the password should be a password or conpassword match with password."
},
field1: {
only_any_of: {
matchNone: "Either you give email in this field or you give number in the field2.",
matchMultiple: "You pass the email in this field and also number in the field2. You need to just choose one field.",
makeInvalidEmpty: "Make this field empty."
}
},
field2: {
only_any_of: {
matchNone: "Either you give number in this field or you give email in the field1.",
matchMultiple: "You pass the number in this field and also email in the field2. You need to just choose one field."
}
},
customInput_notRule : "The field must be empty."
},
// callback : function(errors){
// console.log(errors);
// }
}
let obj = {
form: form,
validate,
overwrite: "overwritenone",
overwrite: "overwriteFiles",
resetKeys: ['singleFile', 'multipleFiles[]'],
ajaxSettings: {
url: 'http://localhost/layout/index.php',
// dataType: "json",
success: (data) => {
console.log(data);
},
// contentType : false, no need it to set it
// processData: false
},
};
form.onsubmit = async e => {
e.preventDefault();
let filesObj = await SubmitForm.selectFiles(form);
obj.inputs = [filesObj, { "myinput": "o@gmail.com" }, formdata];
console.log(filesObj);
SubmitForm.justSubmit(obj);
}
Validator.liveVerify(validate);