fixed issue with redis models

This commit is contained in:
2024-08-06 13:11:55 -04:00
parent e38504457c
commit 84db245f4a
20 changed files with 558 additions and 323 deletions
+53 -70
View File
@@ -1,96 +1,79 @@
( function( $ ) {
var settings = {
rule: {
eq: function( value, options ) {
var compare = $( '[name=' + options + ']' ).val();
eq: function(value, options){
var compare = $('[name=' + options + ']').val();
if ( value != compare ) {
return "Miss-match";
}
}
},
form: {
alertCount: false, //pop-up with error count
alertCountMessage: " errors!"
},
processValidation: function ( error_message, $input ) {
if ( typeof error_message == 'undefined' || error_message == true ) {
return;
}
$( '<b>' ).html( ' - ' + error_message ).appendTo( $input.siblings( 'label' ) );
$input.parent().addClass("has-error");
failedCount++;
return false;
}
};
var failedCount = 0;
$.fn.validate = function(event) {
// let thisSettings = $.extend(true, settings, settingsObj);
let hasErrors = false;
function processRule( thisSettings, $input ) {
var attr = $input.attr( 'validate' ).split( ':' ), //array of params
requirement = attr[1],
value = $input.val(), //link to input value
rule = attr[0];
if(this.is('[validate]')) return this.validateField(event);
$input.siblings( 'label' ).children( 'b' ).remove(); //removes old error
$input.parent().removeClass( "has-error" ); //removes has-error class
if(!this.attr('isValid')){
console.log('adding reset event')
this.on('reset', function(){
$(this).attr('isValid', false);
$(this).validateClear();
})
}
this.find('[validate]').each(function(){
if(!$(this).validateField()) hasErrors = true;
});
this.attr('isValid', !hasErrors);
if(hasErrors && event) event.preventDefault();
return !hasErrors;
};
$.fn.validateClear = function(){
$(this).find('input').each(function(){
$(this).removeClass('is-invalid');
$(this).removeClass('is-valid');
})
}
$.fn.validateField = function(){
var attr = this.attr('validate').split(':'); //array of params
var rule = attr[0];
var options = attr[1];
var value = this.val(); //link to input value
var message;
//checks if field is required, and length
if (isNaN(requirement) === false && requirement && value.length < requirement) {
return thisSettings.processValidation( 'Must be ' + requirement + ' characters', $input );
if(!isNaN(options) && value.length < options){
message = `Must be ${options} characters`;
}
//checks if empty to stop processing
if ( isNaN( requirement ) === false && value.length === 0 ) {
return;
if(!isNaN(options) && value.length === 0) {
}else if(rule in settings.rule){
let message = settings.rule[rule].apply(this, [value, options]);
}
if ( rule in thisSettings.rule ) {
return thisSettings.processValidation( thisSettings.rule[rule].apply( this, [value, requirement] ), $input );
}
this.validateMessage(message)
return !message;
}
$.fn.validate = function( settingsObj, event ) {
event = event || window.event;
failedCount = 0;
var thisForm = false,
thisSettings = $.extend( true, settings, settingsObj );
if ( this.is( '[validate]' ) ) {
processRule( thisSettings, this );
} else {
thisForm = true;
this.find( '[validate]' ).each( function () {
if(!processRule( thisSettings, $( this ) )){
// failedCount++;
}
});
}
this.attr('isValid', !failedCount);
if ( failedCount === 0 ) { //no errors
return true;
} else { //errors
if ( thisForm ){
if(thisSettings.form.alertCount){
alert( failedCount + thisSettings.form.alertCountMessage );
}
/* if(event) event.returnValue = false;
if(event) event.preventDefault();
return false;
if(event.preventDefault) if(event)*/
//event.returnValue = false;
event.preventDefault();
event.defaultPrevented;
}
return false;
$.fn.validateMessage = function(message){
if(message && message !== true){
this.closest('.form-group').find('b.invalid-feedback').html(message);
this.addClass('is-invalid');
}else{
this.removeClass('is-invalid');
this.addClass('is-valid');
}
return this;
};
jQuery.extend({