📄 form.js
字号:
if(this.hasFeature('zpFormAllowedChars')){this.setValueFromField();}}if(this.dropDown){this.dropDown.hide();}return true;};Zapatec.Form.Field.prototype.keypress=function(evt){if(!this.isEditing){return false;}if(!evt){evt=window.event;}this.fireEvent("keypress",evt);this.fireEvent("all",evt,"keypress");this.form.fireEvent("keypress",evt);this.form.fireEvent("all",evt,"keypress");if(this.hasFeature('zpFormAllowedChars')){if(this.processFunctionalKeys(evt)==true){return true;}var tmpArr=Zapatec.Utils.getCharFromEvent(evt)var charCode=tmpArr.charCode;var newChar=tmpArr.chr;if((Zapatec.Form.Utils.isSpecialKey(charCode,newChar)||charCode==8||charCode==46)){return true;}var allowed=new RegExp('['+this.getFeature('zpFormAllowedChars')+']');this.setValueFromField();if(!(allowed.test(newChar))){Zapatec.Utils.addClass(this.field,"zpWrongValue");this.field.readonly=true;var self=this;setTimeout(function(){Zapatec.Utils.removeClass(self.field,"zpWrongValue");self.field.readonly=false;},100);return false;}return true;}if(this.hasFeature("zpFormMask")){var self=this;var tmpArr=Zapatec.Utils.getCharFromEvent(evt)var charCode=tmpArr.charCode;var newChar=tmpArr.chr;if(this.processFunctionalKeys(evt)==true){return true;}this.setValueFromField();var pos=this.getSelectionStart();if(charCode==null&&newChar==null){return false;}if(!Zapatec.is_ie){if(Zapatec.Form.Utils.isSpecialKey(charCode,newChar)){return true;}if(this.processCustomKeys(charCode)==false){return false;}}if(typeof(this.chars[pos])=='string'){var newPos=this.getNextAvailablePosition(pos);if(newPos==null||newPos==pos)return false;this.setCaretPosition(newPos);pos=newPos;}if(pos>=this.chars.length||typeof(this.chars[pos])!='string'&&!newChar.match(this.chars[pos])||typeof(this.chars[pos])=='string'&&newChar!=this.chars[pos]){Zapatec.Utils.addClass(this.field,"zpWrongValue");this.field.readonly=true;setTimeout(function(){Zapatec.Utils.removeClass(self.field,"zpWrongValue");self.field.readonly=false;},100);this.setValue();this.setCaretPosition(pos);}else{this.enteredValue[pos]=newChar;this.setValue();var newPos=this.getNextAvailablePosition(pos);if(newPos==null){newPos=pos+1;}this.setCaretPosition(newPos);}if(evt&&evt.preventDefault){evt.preventDefault();}return false;}return true;};Zapatec.Form.Field.prototype.keyup=function(evt){if(!this.isEditing){return false;}if(!evt){evt=window.event;}this.fireEvent("keyUp",evt);this.fireEvent("all",evt,"keyup");this.form.fireEvent("keyUp",evt);this.form.fireEvent("all",evt,"keyup");if(evt){var tmp=Zapatec.Utils.getCharFromEvent(evt);if(Zapatec.Form.Utils.isSpecialKey(tmp.charCode,tmp.chr)||((tmp.charCode==8||tmp.charCode==46)&&this.state.lastSelectionStart!=this.state.lastSelectionEnd)){return true;}}this.validate();if(this.hasFeature("zpFormAutoComplete")||this.hasFeature("zpFormAutoCompleteStrict")){this.autoCompleteValue(this.getAutoCompleteOptions());}this.keyPressCounter++;var self=this;setTimeout(function(){self.runDelayedActions()},Zapatec.Form.Field.DELAYED_INTERVAL);return true;};Zapatec.Form.Field.prototype.focus=function(evt){if(!evt){evt=window.event;}if(this.field.readOnly){return;}this.isEditing=true;this.firstRun=false;if(this.hasFeature("zpFormMask")){if(this.isEmpty()){this.setValue();this.setCaretPosition(0);}}if(this.isBooleanField){this.booleanChanged(evt);}this.fireEvent("focus",evt);this.fireEvent("all",evt,"focus");this.form.fireEvent("focus",evt);this.form.fireEvent("all",evt,"focus");this.validate();};Zapatec.Form.Field.prototype.blur=function(evt){if(!evt){evt=window.event;}if(this.hasFeature("zpFormMask")&&!this.isFilled()){Zapatec.Form.Utils.setValue(this.field,"");}if(!this.isEditing){return;}this.isEditing=false;if(this.hasFeature("zpFormAllowedChars")){this.setValueFromField(true);}this.fireEvent("blur",evt);this.fireEvent("all",evt,"blur");this.form.fireEvent("blur",evt);this.form.fireEvent("all",evt,"blur");this.validate();};Zapatec.Form.Field.prototype.validate=function(onlyValidate){if(!this.field.className||(this.field.disabled&&!this.firstRun)){return null;}var message=null;var errors=[];var isRequired=this.isRequired();var isEmpty=this.isEmpty();if(this.isBooleanField&&!isRequired){isEmpty=this.field.checked;}if(this.firstRun&&!isEmpty||this.field.disabled){this.firstRun=false;}var validatorUsed=isRequired;var validatorName=null;var l10nMessage=null;var messageArgument=null;function addError(self,errors,validatorName,l10nMessage,messageArgument){if(!validatorName){return null}var message=self.hasFeature(validatorName+"Error")?self.getFeature(validatorName+"Error"):self.getMessage(l10nMessage,messageArgument);if(!message){message=self.getMessage(l10nMessage,messageArgument);}message=message.replace(/&/g,'&').replace(/</g,'<').replace(/\>/g,'>');errors.push({field:self.field,errorMessage:message,validator:validatorName});return message;}if(isEmpty){validatorUsed=true;if(isRequired){validatorName="zpFormRequired";l10nMessage="isRequiredError";}}else{for(var vName in this.features){if(vName=='zpFormMask'){validatorUsed=true;if(!this.isMaskFullyFilled()){validatorName="zpFormMask";l10nMessage='maskNotFilledError';messageArgument=this.getFeature("zpFormMask");break;}}if(vName=='zpFormAutoCompleteStrict'){validatorUsed=true;var found=false;var currVal=this.getValue();for(var ii=this.autoCompleteOptions.length-1;ii>=0;ii--){if(currVal==this.autoCompleteOptions[ii]){found=true;break;}}if(!found){validatorName="zpFormAutoCompleteStrict";l10nMessage="noSuchAutoCompleteValueError";}}if(typeof(Zapatec.Form.dataTypes[vName])!='undefined'){validatorUsed=true;var validator=Zapatec.Form.dataTypes[vName];var validatorPassed=true;messageArgument=this.getFeature(vName);if(validator.regex){validatorPassed=validator.regex.test(this.getValue());}else if(validator.func){validatorPassed=validator.func(this.getValue(),this.getFeature(vName));}if(!validatorPassed){validatorName=vName;l10nMessage=validator.error;}}if(validatorName){message=addError(this,errors,validatorName,l10nMessage,messageArgument)||message;validatorName=null;}}if(this.ajaxError!=null){validatorUsed=true;validatorName="zpFormValidate";l10nMessage=this.ajaxError;}}message=addError(this,errors,validatorName,l10nMessage,messageArgument)||message;if(!onlyValidate&&validatorUsed){this.setImageStatus(message,isEmpty);}return errors;};Zapatec.Form.Field.prototype.setImageStatus=function(status,isEmpty){var isRequired=this.isRequired();if(typeof(isEmpty)=='undefined'){isEmpty=this.isEmpty();}this.requiredMark.className=Zapatec.Form.IGNORE_CLASSNAME+(isRequired?' zpIsRequired':' zpNotRequired');this.editingMark.className=Zapatec.Form.IGNORE_CLASSNAME;this.emptyMark.className=Zapatec.Form.IGNORE_CLASSNAME;this.validMark.className=Zapatec.Form.IGNORE_CLASSNAME;this.errorText.innerHTML="";if(this.config.formConfig.strict){if(status==null){this.form.toggleSubmits(this.form.validate()!=null);}else{this.form.toggleSubmits(true);}}if(!this.firstRun&&(isRequired&&isEmpty||!isEmpty)){this.editingMark.className=Zapatec.Form.IGNORE_CLASSNAME+(this.isEditing?' zpIsEditing':' zpNotEditing');this.emptyMark.className=Zapatec.Form.IGNORE_CLASSNAME+(isEmpty?' zpIsEmpty':' zpNotEmpty');this.validMark.className=Zapatec.Form.IGNORE_CLASSNAME+(!status?' zpIsValid':' zpNotValid');if((isRequired&&isEmpty&&this.isEditing)||(this.isEditing&&!this.config.formConfig.displayErrorWhileTyping)){if(!(this.config.formConfig.showErrors=='tooltip'&&Zapatec.Tooltip)&&!this.isBooleanField){status=null;}}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){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{this.statusImg.title=status;}}}};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;}};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);}};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();}};Zapatec.Form.Field.prototype.hasFeature=function(feature){if(!feature||typeof(this.features[feature])=='undefined'){return false;}return true;};Zapatec.Form.Field.prototype.getFeature=function(feature){return this.features[feature];};Zapatec.Form.Field.prototype.setFeature=function(feature,value){this.features[feature]=value;};Zapatec.Form.Field.prototype.isRequired=function(){var isRequired=this.getFeature("zpFormRequired");return isRequired;}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;};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;};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'){this.field.setSelectionRange(startPos,endPos);return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -