⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form-field.js

📁 zapatec suite 最新版 20070204,非常棒的ajax widgets 工具包
💻 JS
📖 第 1 页 / 共 4 页
字号:
			if(				!(					this.config.formConfig.showErrors == 'tooltip' && 					Zapatec.Tooltip				) && 				!this.isBooleanField			){				status = null;			}		}		// Error status text handling.		if(!status){			if(typeof(this.config.formConfig.showErrors) == 'function'){				this.config.formConfig.showErrors(this.field);			} else if(this.tooltip){				this.tooltip.hide();			} else if(this.errorText){				this.errorText.style.display = "none";			}		} else if(status) {			if (				this.config.formConfig.showErrors == 'beforeField' ||				this.config.formConfig.showErrors == 'afterField'			){				this.errorText.style.display = "";				this.errorText.innerHTML = status;			} else if(typeof(this.config.formConfig.showErrors) == 'function'){				this.config.formConfig.showErrors(this.field, status);			} else if(this.config.formConfig.showErrors == 'tooltip' && Zapatec.Tooltip){				// Create a tooltip on the img.				if (!this.tooltip) {					this.tooltip = new Zapatec.Tooltip({						target: this.requiredMark, 						content: status,						parent: this.form.container					});				}								this.tooltip.setContent(status);								if(this.isEditing){					var offs = Zapatec.Utils.getElementOffset(this.requiredMark);					this.tooltip.show(offs.left, offs.top + offs.height);				} else {					this.tooltip.hide();				}			} else {				// Use default browser tooltip				this.statusImg.title = status;			}		}	}};/** * @private * Check if field is empty * @return true, if field is empty(for zpFormMask fields field is empty - * only if user don't enter any symbol to it) * @type boolean */Zapatec.Form.Field.prototype.isEmpty = function(){	if(!this.hasFeature("zpFormMask")){		if(this.isBooleanField){			var elements = this.form.container.elements;			for(var ii = elements.length - 1; ii >= 0; ii--){				var element = elements[ii];				 				if(element.name == this.field.name && element.checked){					return false;				}			}			return true;		} else {			var currVal = this.getValue();			return (currVal == null || currVal.length == 0);		}	} else {		for(ii = 0; ii < this.enteredValue.length; ii++){			if(typeof(this.chars[ii]) != 'string' && this.enteredValue[ii] != null){				return false;			}		}		return true;	}};/** * @private * Check if at least one character is entered * @return true, if at least one character is entered * @type boolean */Zapatec.Form.Field.prototype.isFilled = function(){	if(this.hasFeature("zpFormMask")){		for(ii = 0; ii < this.enteredValue.length; ii++){			if(typeof(this.chars[ii]) != 'string' && this.enteredValue[ii] != null){				return true;			}		}		return false;	} else {		var currVal = this.getValue();		return (currVal != null && currVal.length > 0);	}};/** * @private * Checks if mask is fully entered * @return true if mask is fully filled  * @type boolean */Zapatec.Form.Field.prototype.isMaskFullyFilled = function(){	if(this.hasFeature("zpFormMask")){		for(ii = 0; ii < this.enteredValue.length; ii++){			if(typeof(this.chars[ii]) != 'string' && this.enteredValue[ii] == null){				return false;			}		}		return true;	} else {		return this.isFilled();	}};/** * @private * Checks if field has given feature. * @param feature - [string] feature name * @return true if field has given feature * @type boolean */Zapatec.Form.Field.prototype.hasFeature = function(feature){	if(		!feature ||		typeof(this.features[feature]) == 'undefined'	){		return false;	}	return true;};/** * @private * Returns value for given feature name * @param feature - [string] feature name * @return value for given feature name * @type String */Zapatec.Form.Field.prototype.getFeature = function(feature){	return this.features[feature];};/** * @private * Set value for given feature name * @param feature - [string] feature name * @param value {Object} Value to set */Zapatec.Form.Field.prototype.setFeature = function(feature, value){	this.features[feature] = value;};Zapatec.Form.Field.prototype.isRequired = function(){	var isRequired = this.getFeature("zpFormRequired");	// TODO provide zpFormRequiredWhen functionality here	return isRequired;}/* * @private * zpFormMask related function. * Get position of next unfilled character in a mask.. * @return position of next unfilled mask char into mask. Returns null if such *	character not found. * @type int */Zapatec.Form.Field.prototype.getNextAvailablePosition = function(pos){	if(pos + 1 >= this.enteredValue.length){		return null;	}	if(typeof(this.chars[pos + 1]) == 'string'){		return this.getNextAvailablePosition(pos + 1);	}	return pos + 1;};/** * @private * zpFormMask related function. * Get position of next unfilled character in a mask. * @return position of previous unfilled mask char into mask. Returns null if  *	such character not found. */Zapatec.Form.Field.prototype.getPrevAvailablePosition = function(pos){	if(pos - 1 < 0){		return null;	}	if(typeof(this.chars[pos - 1]) == 'string'){		return this.getPrevAvailablePosition(pos - 1);	}	return pos - 1;};/** * @private * zpFormMask related function. * Set selection inside INPUT element * @param startPos {int} start of selection(required). * @param endPos {int} end of selection(nonrequired. equal to startPos by default) */Zapatec.Form.Field.prototype.setCaretPosition = function(startPos, endPos){	var valLength = this.getValue().length;	if(!this.isSelectionAppliable() || !this.isEditing){		return null;	}	if(isNaN(parseInt(startPos))){		return false;	} else {		startPos = parseInt(startPos);		if(startPos < 0){			startPos = 0;		} else if(startPos > valLength){			startPos = valLength;		}	}	if(endPos == null || isNaN(parseInt(endPos)) || parseInt(endPos) < startPos){		endPos = startPos;	} else {		endPos = parseInt(endPos);		if(endPos < 0){			endPos = 0;		} else if(endPos > valLength){			endPos = valLength;		}	}	if(typeof(this.field.createTextRange) == "object"){		var range = this.field.createTextRange();		range.moveEnd("character", endPos - this.getValue().length);		range.moveStart("character", startPos);		range.select();		return true;	} else if (typeof(this.field.setSelectionRange) == 'function'){		// mozilla, opera, safari		this.field.setSelectionRange(startPos, endPos);		return true;	}	return false;};/** * @private * zpFormMask related function. * Get start position of selection in INPUT element. * @return start position of selection in INPUT element. * @type int */Zapatec.Form.Field.prototype.getSelectionStart = function(){	if(this.field.disabled || !this.isSelectionAppliable() || !this.isEditing){		return 0;	}	if (document.selection) {		// IE black magic		return Math.abs(			document.selection.createRange().moveStart("character", -1000000)		);	} else if (typeof(this.field.selectionStart) != "undefined"){		// mozilla and opera		var selStart = this.field.selectionStart;			// Safari bug when field is focused for first time		if(selStart == 2147483647){			selStart = 0;		}		return selStart;	}		return 0;};/** * @private * zpFormMask related function. * Get end position of selection in INPUT element. * @return end position of selection in INPUT element. * @type int */Zapatec.Form.Field.prototype.getSelectionEnd = function(){	if(this.field.disabled || !this.isSelectionAppliable() || !this.isEditing){		return 0;	}	if (document.selection) {		// IE black magic		return this.field.value.length - Math.abs(			document.selection.createRange().moveEnd("character", 1000000)		);	} else if (typeof(this.field.selectionEnd) != "undefined") {		// mozilla and opera		return this.field.selectionEnd;	} 	return 0;};/** * @private * zpFormMask related function. * Processes backspace and delete keys. * @param charCode {int} code of the key that was pressed. */Zapatec.Form.Field.prototype.processCustomKeys = function(charCode){	var selStart = this.getSelectionStart();	var selEnd = this.getSelectionEnd();	if(selStart == selEnd){		if(charCode == 8){ // backspace			var newPos = this.getPrevAvailablePosition(selStart);			if(newPos == null || newPos == selStart){				return false;			}			this.enteredValue[newPos] = null;			this.setValue();			this.setCaretPosition(newPos + (Zapatec.is_opera ? 1 : 0));			return false;		}		if(charCode == 46){ // delete			if(typeof(this.chars[selStart]) == 'string'){				return false;			}			this.enteredValue[selStart] = null;			this.setValue();			this.setCaretPosition(selStart)			return false;		}	} else {		if(charCode == 8 || charCode == 46){ // backspace			for(var ii = selStart; ii < selEnd; ii++){				if(typeof(this.chars[ii]) != 'string'){					this.enteredValue[ii] = null;				}			}			this.setValue();			this.setCaretPosition(selStart + (Zapatec.is_opera ? 1 : 0));			return false;		}	}	return true;};/** * @private * zpFormMask related function. * Custom processing for alt, ctrl and shift keys * @param {Event} event object */Zapatec.Form.Field.prototype.processFunctionalKeys = function(evt){	var tmpArr = Zapatec.Utils.getCharFromEvent(evt)	var charCode = tmpArr.charCode;	var newChar = tmpArr.chr;	if(evt.ctrlKey || (typeof(evt.metaKey) != 'undefined' && evt.metaKey)){		// custom processing of ctrl+backspace and ctrl+delete shortcuts		if(charCode == 8){			// backspace			this.setCaretPosition(0, this.getSelectionStart());			return false;		} else if(charCode == 46){			// delete			this.setCaretPosition(this.getSelectionStart(), this.getValue().length);			return false;		} else if(newChar == 'v' || newChar == 'V'){			this.setValueFromField();			return true;		}		return true;	} else if(evt.shiftKey){		if(charCode == 37 || charCode == 39){ // left/right arrow			return true;		} else if(charCode == 45){ // insert			this.setValueFromField();			return true;		}	} else if(evt.altKey){		return true;	}	return false;};/** * @private * zpFormMask related function. * Sets field value and value of INPUT element(this captures paste into field). * @param runImmediately {boolean} If false - wait 1ms before execution.  *	Sometimes this is needed when you want to be sure that last keystrokes are *	recorded into field value. */Zapatec.Form.Field.prototype.setValueFromField = function(runImmediately){	if(!runImmediately){		var self = this;			setTimeout(			function(){				self.setValueFromField(true);			},		1);		return;	}	var selStart = this.getSelectionStart();	var selEnd = this.getSelectionEnd();	var editMode = this.isEditing;	this.isEditing = true;	this.setValue(Zapatec.Form.Utils.getValue(this.field));	if(this.isBooleanField){		this.booleanChanged();	}	this.isEditing = editMode;	this.validate();	if(!this.isEditing){		this.blur();	} else {		this.setCaretPosition(selStart, selEnd);	}};/** * @private * Get value of current field. * @return value of current field. * @type String */Zapatec.Form.Field.prototype.getValue = function(){	return Zapatec.Form.Utils.getValue(this.field);}/** * @private * Sets value of current field * @param value [String] value to set * @return Value that was written into field. * @type String */Zapatec.Form.Field.prototype.setValue = function(value){	if(value == null){		value = "";	}	// remove invalid characters from the value	if (this.hasFeature('zpFormAllowedChars')){		var notallowed = new RegExp('[^' + this.getFeature('zpFormAllowedChars') + ']', 'g');		value = value.replace(notallowed, "");	}	// if field has zpFormMask mark - this is special case	if(this.hasFeature('zpFormMask')){		var val = "";		if(this.isEditing || this.isFilled()){			for(ii = 0; ii < this.chars.length; ii++){				if(ii < value.length){					// if value is given - fill this.enteredValue with it.					if(typeof(this.chars[ii]) != "string"){						if(this.chars[ii].test(value.charAt(ii))){							this.enteredValue[ii] = value.charAt(ii);							val += value.charAt(ii);						} else {							this.enteredValue[ii] = null;							if (this.config.formConfig.maskPlaceholder) {								val += this.config.formConfig.maskPlaceholder;							}						}					} else {						this.enteredValue[ii] = this.chars[ii];						val += this.chars[ii];					}				} else if(arguments.length > 0){					// if value were given - clear rest of the characters					if(typeof(this.chars[ii]) == 'string'){						val += this.chars[ii];					} else {						this.enteredValue[ii] = null;						if (this.config.formConfig.maskPlaceholder) {							val += this.config.formConfig.maskPlaceholder;						}					}				} else {					// if no value were given - then form masked value from internal arrays					if(typeof(this.chars[ii]) == 'string'){						val += this.chars[ii];					} else {						var tempHolderString;						if (this.config.formConfig.maskPlaceholder) {							tempHolderString = this.config.formConfig.maskPlaceholder;						} else {							tempHolderString = "";						}						val += this.enteredValue[ii] == null ? tempHolderString : this.enteredValue[ii];					}				}			}		}		value = val;	}	// For textarea - we must restore scrolling position in textarea.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -