Add project files.
This commit is contained in:
263
assets/js/pages/crud/forms/validation/form-controls.js
Normal file
263
assets/js/pages/crud/forms/validation/form-controls.js
Normal file
@ -0,0 +1,263 @@
|
||||
// Class definition
|
||||
var KTFormControls = function () {
|
||||
// Private functions
|
||||
var _initDemo1 = function () {
|
||||
FormValidation.formValidation(
|
||||
document.getElementById('kt_form_1'),
|
||||
{
|
||||
fields: {
|
||||
email: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'ایمیل لازم است'
|
||||
},
|
||||
emailAddress: {
|
||||
message: "مقدار یک آدرس ایمیل معتبر نیست"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
url: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'آدرس وب سایت لازم است'
|
||||
},
|
||||
uri: {
|
||||
message: "آدرس وب سایت معتبر نیست"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
digits: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'ارقام لازم است'
|
||||
},
|
||||
digits: {
|
||||
message: "مقدار یک رقم معتبر نیست"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
creditcard: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "شماره کارت اعتباری لازم است"
|
||||
},
|
||||
creditCard: {
|
||||
message: "شماره کارت اعتباری معتبر نیست"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
phone: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'شماره تلفن ایالات متحده مورد نیاز است'
|
||||
},
|
||||
phone: {
|
||||
country: 'US',
|
||||
message: "این مقدار شماره تلفن معتبر ایالات متحده نیست"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
option: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'لطفا یک گزینه را انتخاب کنید'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
options: {
|
||||
validators: {
|
||||
choice: {
|
||||
min:2,
|
||||
max:5,
|
||||
message: "لطفا حداقل 2 و حداکثر 5 گزینه را انتخاب کنید"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
memo: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "لطفا متن یادداشت را وارد کنید"
|
||||
},
|
||||
stringLength: {
|
||||
min:50,
|
||||
max:100,
|
||||
message: "لطفاً یک فهرست را در محدوده متن 50 و 100 وارد کنید"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
checkbox: {
|
||||
validators: {
|
||||
choice: {
|
||||
min:1,
|
||||
message: "لطفا با مهربانی این را بررسی کنید"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
checkboxes: {
|
||||
validators: {
|
||||
choice: {
|
||||
min:2,
|
||||
max:5,
|
||||
message: "لطفا حداقل 1 و حداکثر 2 گزینه را بررسی کنید"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
radios: {
|
||||
validators: {
|
||||
choice: {
|
||||
min:1,
|
||||
message: "لطفا با مهربانی این را بررسی کنید"
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
plugins: { //Learn more: https://formvalidation.io/guide/plugins
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
// Bootstrap Framework Integration
|
||||
bootstrap: new FormValidation.plugins.Bootstrap(),
|
||||
// Validate fields when clicking the Submit button
|
||||
submitButton: new FormValidation.plugins.SubmitButton(),
|
||||
// Submit the form when all fields are valid
|
||||
defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var _initDemo2 = function () {
|
||||
FormValidation.formValidation(
|
||||
document.getElementById('kt_form_2'),
|
||||
{
|
||||
fields: {
|
||||
billing_card_name: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "نام دارنده کارت لازم است"
|
||||
}
|
||||
}
|
||||
},
|
||||
billing_card_number: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "شماره کارت اعتباری لازم است"
|
||||
},
|
||||
creditCard: {
|
||||
message: "شماره کارت اعتباری معتبر نیست"
|
||||
}
|
||||
}
|
||||
},
|
||||
billing_card_exp_month: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "ماه انقضا لازم است"
|
||||
}
|
||||
}
|
||||
},
|
||||
billing_card_exp_year: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "سال انقضا لازم است"
|
||||
}
|
||||
}
|
||||
},
|
||||
billing_card_cvv: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "CVV لازم است"
|
||||
},
|
||||
digits: {
|
||||
message: 'مقدار CVV یک رقم معتبر نیست'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
billing_address_1: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'آدرس 1 الزامی است'
|
||||
}
|
||||
}
|
||||
},
|
||||
billing_city: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'شهر 1 مورد نیاز است'
|
||||
}
|
||||
}
|
||||
},
|
||||
billing_state: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "حالت 1 لازم است"
|
||||
}
|
||||
}
|
||||
},
|
||||
billing_zip: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'کد پستی لازم است'
|
||||
},
|
||||
zipCode: {
|
||||
country: 'US',
|
||||
message: "مقدار کد پستی نامعتبر است"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
billing_delivery: {
|
||||
validators: {
|
||||
choice: {
|
||||
min:1,
|
||||
message: 'لطفا نوع تحویل را لطفاً انتخاب کنید'
|
||||
}
|
||||
}
|
||||
},
|
||||
package: {
|
||||
validators: {
|
||||
choice: {
|
||||
min:1,
|
||||
message: "لطفاً نوع بسته را انتخاب کنید"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
// Validate fields when clicking the Submit button
|
||||
submitButton: new FormValidation.plugins.SubmitButton(),
|
||||
// Submit the form when all fields are valid
|
||||
defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
|
||||
// Bootstrap Framework Integration
|
||||
bootstrap: new FormValidation.plugins.Bootstrap({
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: '',
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
// public functions
|
||||
init: function() {
|
||||
_initDemo1();
|
||||
_initDemo2();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
KTFormControls.init();
|
||||
});
|
||||
199
assets/js/pages/crud/forms/validation/form-widgets.js
Normal file
199
assets/js/pages/crud/forms/validation/form-widgets.js
Normal file
@ -0,0 +1,199 @@
|
||||
// Class definition
|
||||
|
||||
var KTFormWidgetsValidation = function () {
|
||||
// Private functions
|
||||
var validator;
|
||||
|
||||
var _initWidgets = function() {
|
||||
// Initialize Plugins
|
||||
// Datepicker
|
||||
$('#kt_datepicker').datepicker({
|
||||
todayHighlight: true,
|
||||
templates: {
|
||||
leftArrow: '<i class=\"la la-angle-left\"></i>',
|
||||
rightArrow: '<i class=\"la la-angle-right\"></i>'
|
||||
}
|
||||
}).on('changeDate', function(e) {
|
||||
// Revalidate field
|
||||
validator.revalidateField('date');
|
||||
});
|
||||
|
||||
// Datetimepicker
|
||||
$('#kt_datetimepicker').datetimepicker({
|
||||
pickerPosition: 'bottom-left',
|
||||
todayHighlight: true,
|
||||
autoclose: true,
|
||||
format: 'yyyy.mm.dd hh:ii'
|
||||
});
|
||||
|
||||
$('#kt_datetimepicker').change(function() {
|
||||
// Revalidate field
|
||||
validator.revalidateField('datetime');
|
||||
});
|
||||
|
||||
// Timepicker
|
||||
$('#kt_timepicker').timepicker({
|
||||
minuteStep: 1,
|
||||
showSeconds: true,
|
||||
showMeridian: true
|
||||
});
|
||||
|
||||
$('#kt_timepicker').change(function() {
|
||||
// Revalidate field
|
||||
validator.revalidateField('time');
|
||||
});
|
||||
|
||||
// Daterangepicker
|
||||
$('#kt_daterangepicker').daterangepicker({
|
||||
buttonClasses: ' btn',
|
||||
applyClass: 'btn-primary',
|
||||
cancelClass: 'btn-light-primary'
|
||||
}, function(start, end, label) {
|
||||
var input = $('#kt_daterangepicker').find('.form-control');
|
||||
input.val( start.format('YYYY/MM/DD') + ' / ' + end.format('YYYY/MM/DD'));
|
||||
|
||||
// Revalidate field
|
||||
validator.revalidateField('daterangepicker');
|
||||
});
|
||||
|
||||
// Bootstrap Switch
|
||||
$('[data-switch=true]').bootstrapSwitch();
|
||||
$('[data-switch=true]').on('switchChange.bootstrapSwitch', function() {
|
||||
// Revalidate field
|
||||
validator.revalidateField('switch');
|
||||
});
|
||||
|
||||
// Bootstrap Select
|
||||
$('#kt_bootstrap_select').selectpicker();
|
||||
$('#kt_bootstrap_select').on('changed.bs.select', function() {
|
||||
// Revalidate field
|
||||
validator.revalidateField('select');
|
||||
});
|
||||
|
||||
// Select2
|
||||
$('#kt_select2').select2({
|
||||
placeholder: "انتخاب یک گزینه",
|
||||
});
|
||||
|
||||
$('#kt_select2').on('change', function(){
|
||||
// Revalidate field
|
||||
validator.revalidateField('select2');
|
||||
});
|
||||
|
||||
// Typeahead
|
||||
var countries = new Bloodhound({
|
||||
datumTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
prefetch: HOST_URL + '/api/?file=typeahead/countries.json'
|
||||
});
|
||||
|
||||
$('#kt_typeahead').typeahead(null, {
|
||||
name: 'countries',
|
||||
source: countries
|
||||
});
|
||||
|
||||
$('#kt_typeahead').bind('typeahead:select', function(ev, suggestion) {
|
||||
// Revalidate field
|
||||
validator.revalidateField('typeahead');
|
||||
});
|
||||
}
|
||||
|
||||
var _initValidation = function () {
|
||||
// Validation Rules
|
||||
validator = FormValidation.formValidation(
|
||||
document.getElementById('kt_form'),
|
||||
{
|
||||
fields: {
|
||||
date: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'تاریخ لازم است'
|
||||
}
|
||||
}
|
||||
},
|
||||
daterangepicker: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'رنج تاریخ را وارد کنید'
|
||||
}
|
||||
}
|
||||
},
|
||||
datetime: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "تاریخ و زمان لازم است"
|
||||
}
|
||||
}
|
||||
},
|
||||
time: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'زمان لازم است'
|
||||
}
|
||||
}
|
||||
},
|
||||
select: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "انتخاب لازم است"
|
||||
}
|
||||
}
|
||||
},
|
||||
select2: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "انتخاب لازم است"
|
||||
}
|
||||
}
|
||||
},
|
||||
typeahead: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'تایپ پیش نیاز است'
|
||||
}
|
||||
}
|
||||
},
|
||||
switch: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'تایپ پیش نیاز است'
|
||||
}
|
||||
}
|
||||
},
|
||||
markdown: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'تایپ پیش نیاز است'
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
// Validate fields when clicking the Submit button
|
||||
submitButton: new FormValidation.plugins.SubmitButton(),
|
||||
// Submit the form when all fields are valid
|
||||
defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
|
||||
// Bootstrap Framework Integration
|
||||
bootstrap: new FormValidation.plugins.Bootstrap({
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: '',
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
// public functions
|
||||
init: function() {
|
||||
_initWidgets();
|
||||
_initValidation();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
KTFormWidgetsValidation.init();
|
||||
});
|
||||
Reference in New Issue
Block a user