CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-extsys / src / main / webapp / extsys / vnfm / js / vnfm-validate.js
1 /*\r
2  * Copyright 2016-2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 $(function () {\r
17     var form = $('#vnfm_form');\r
18     var error = $('.alert-danger', form);\r
19     var success = $('.alert-success', form);\r
20 \r
21     form.validate({\r
22         doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.\r
23         errorElement: 'span', //default input error message container\r
24         errorClass: 'help-block', // default input error message class\r
25         focusInvalid: false, // do not focus the last invalid input\r
26         rules: {\r
27             name: {\r
28                 required: true,\r
29                 maxlength: 20\r
30             },\r
31             type: {\r
32                 required: true,\r
33                 maxlength: 20\r
34             },\r
35             version: {\r
36                 required: true,\r
37                 maxlength: 20\r
38             },\r
39             vendor: {\r
40                 required: true,\r
41                 maxlength: 20\r
42             },\r
43             url: {\r
44                 required: true,\r
45                 url: true\r
46             }\r
47         },\r
48         messages: {\r
49             name: {\r
50                 required: $.i18n.prop("nfv-vnfm-iui-validate-name")\r
51             },\r
52             type: {\r
53                 required: $.i18n.prop("nfv-vnfm-iui-validate-type")\r
54             },\r
55             version: {\r
56                 required: $.i18n.prop("nfv-vnfm-iui-validate-version")\r
57             },\r
58             vendor: {\r
59                 required: $.i18n.prop("nfv-vnfm-iui-validate-vendor")\r
60             },\r
61             url: {\r
62                 required: $.i18n.prop("nfv-vnfm-iui-validate-url-required"),\r
63                 url: $.i18n.prop("nfv-vnfm-iui-validate-url")\r
64             }\r
65         },\r
66         errorPlacement: function (error, element) { // render error placement for each input type\r
67             error.insertAfter(element); // for other inputs, just perform default behavior\r
68         },\r
69         invalidHandler: function (event, validator) { //display error alert on form submit   \r
70             success.hide();\r
71             error.show();\r
72         },\r
73         highlight: function (element) { // hightlight error inputs\r
74             $(element).closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group\r
75         },\r
76         unhighlight: function (element) { // revert the change done by hightlight\r
77             $(element).closest('.form-group').removeClass('has-error'); // set error class to the control group\r
78         },\r
79         success: function (label) {\r
80             label.addClass('valid') // mark the current input as valid and display OK icon\r
81                 .closest('.form-group').removeClass('has-error'); // set success class to the control group\r
82         },\r
83         submitHandler: function (form) {\r
84             success.show();\r
85             error.hide();\r
86             //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax\r
87         }\r
88     });\r
89 });