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