📄 form.js
字号:
return false;};Zapatec.Form.Field.prototype.getSelectionStart=function(){if(this.field.disabled||!this.isSelectionAppliable()||!this.isEditing){return 0;}if(document.selection){return Math.abs(document.selection.createRange().moveStart("character",-1000000));}else if(typeof(this.field.selectionStart)!="undefined"){var selStart=this.field.selectionStart;if(selStart==2147483647){selStart=0;}return selStart;}return 0;};Zapatec.Form.Field.prototype.getSelectionEnd=function(){if(this.field.disabled||!this.isSelectionAppliable()||!this.isEditing){return 0;}if(document.selection){return this.field.value.length-Math.abs(document.selection.createRange().moveEnd("character",1000000));}else if(typeof(this.field.selectionEnd)!="undefined"){return this.field.selectionEnd;}return 0;};Zapatec.Form.Field.prototype.processCustomKeys=function(charCode){var selStart=this.getSelectionStart();var selEnd=this.getSelectionEnd();if(selStart==selEnd){if(charCode==8){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){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){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;};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)){if(charCode==8){this.setCaretPosition(0,this.getSelectionStart());return false;}else if(charCode==46){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){return true;}else if(charCode==45){this.setValueFromField();return true;}}else if(evt.altKey){return true;}return false;};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);}};Zapatec.Form.Field.prototype.getValue=function(){return Zapatec.Form.Utils.getValue(this.field);}Zapatec.Form.Field.prototype.setValue=function(value){if(value==null){value="";}if(this.hasFeature('zpFormAllowedChars')){var notallowed=new RegExp('[^'+this.getFeature('zpFormAllowedChars')+']','g');value=value.replace(notallowed,"");}if(this.hasFeature('zpFormMask')){var val="";if(this.isEditing||this.isFilled()){for(ii=0;ii<this.chars.length;ii++){if(ii<value.length){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(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(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;}var oldScrollTop=null;var oldScrollLeft=null;if(this.field.nodeName.toLowerCase()=='textarea'&&typeof(this.field.scrollTop)!='undefined'){oldScrollTop=this.field.scrollTop;oldScrollLeft=this.field.scrollLeft;}var retVal=Zapatec.Form.Utils.setValue(this.field,value);if(this.field.nodeName.toLowerCase()=='textarea'&&oldScrollTop!=null){this.field.scrollTop=oldScrollTop;this.field.scrollLeft=oldScrollLeft;}return retVal;};Zapatec.Form.Field.prototype.runDelayedActions=function(){this.keyPressCounter--;if(this.keyPressCounter!=0){return null;}this.ajaxValidate();this.suggestValue();this.ajaxFill();};Zapatec.Form.Field.prototype.ajaxValidate=function(){if(!this.hasFeature("zpFormValidate")){return null;}var valid=this.validate();if(!(valid==null||valid!=null&&(valid.length==0||valid.length==1&&valid[0].validator=="zpFormValidate"))){return null;}var submitUrl=this.getFeature("zpFormValidate");var submitMethod=this.getFeature("zpFormValidateMethod");var submitParam=this.getFeature("zpFormValidateParam");var submitQuery=this.getFeature("zpFormValidateQuery");if(typeof(submitMethod)!='string'){submitMethod="GET"}if(typeof(submitParam)!='string'){submitParam=this.field.name;}if(typeof(submitQuery)!='string'){submitQuery="";}submitQuery+="&"+escape(submitParam)+"="+escape(this.getValue());if(submitUrl.indexOf("?")<0){submitUrl+="?";}submitUrl+="&"+Math.random();if(submitMethod=='GET'){submitUrl+="&"+submitQuery;}this.fetchingMark.className="zpIsFetching "+Zapatec.Form.IGNORE_CLASSNAME;var self=this;if(this.config.formConfig.ajaxDebugFunc){this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugSeparator'));this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugValidateTitle',this.field.name));this.config.formConfig.ajaxDebugFunc(submitMethod+" "+submitUrl);this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugQuery',("GET"?"":submitQuery)));}Zapatec.Transport.fetch({url:submitUrl,content:submitMethod=="GET"?null:submitQuery,method:submitMethod,onLoad:function(objText){if(self.config.formConfig.ajaxDebugFunc){self.config.formConfig.ajaxDebugFunc(self.getMessage('ajaxDebugResponse',objText.responseText));}self.fetchingMark.className=Zapatec.Form.IGNORE_CLASSNAME+"zpNotFetching";if(objText.responseText==null){Zapatec.Log({description:self.getMessage('ajaxValidateNoResponseError',objText.responseText)});return null;}var objResponse=Zapatec.Transport.parseJson({strJson:objText.responseText});if(objResponse==null){Zapatec.Log({description:self.getMessage('ajaxValidateCantParseError',objText.responseText)});return null;}if(!objResponse.success){self.ajaxError=typeof(objResponse.generalError)!='string'||objResponse.generalError.length==0?self.getMessage('ajaxValidateValidationError'):objResponse.generalError;}else{self.ajaxError=null;}self.validate();},onError:function(objError){var strError='';if(objError.errorCode){strError+=objError.errorCode+' ';}strError+=objError.errorDescription;self.fetchingMark.className=Zapatec.Form.IGNORE_CLASSNAME+" zpNotFetching";alert(strError);self.ajaxError=null;if(self.config.formConfig.ajaxDebugFunc){self.config.formConfig.ajaxDebugFunc(self.getMessage('ajaxDebugResponseError',strError));}}});};Zapatec.Form.Field.prototype.ajaxFill=function(){if(!this.hasFeature("zpFormFillUrl")){return null;}var submitUrl=this.getFeature("zpFormFillUrl");var submitMethod=this.getFeature("zpFormFillMethod");var submitParam=this.getFeature("zpFormFillParam");var submitQuery=this.getFeature("zpFormFillQuery");if(typeof(submitMethod)!='string'){submitMethod="GET";}if(typeof(submitParam)!='string'){submitParam=this.field.name;}if(typeof(submitQuery)!='string'){submitQuery="";}submitQuery+="&"+escape(submitParam)+"="+escape(this.getValue());if(submitUrl.indexOf("?")<0){submitUrl+="?";}submitUrl+="&"+Math.random();if(submitMethod=='GET'){submitUrl+="&"+submitQuery;}this.fetchingMark.className="zpIsFetching "+Zapatec.Form.IGNORE_CLASSNAME;var self=this;if(this.config.formConfig.ajaxDebugFunc){this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugSeparator'));this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugFillTitle',this.field.name));this.config.formConfig.ajaxDebugFunc(submitMethod+" "+submitUrl);this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugQuery',("GET"?"":submitQuery)));}Zapatec.Transport.fetch({url:submitUrl,content:submitMethod=="GET"?null:submitQuery,method:submitMethod,onLoad:function(objText){if(self.config.formConfig.ajaxDebugFunc){self.config.formConfig.ajaxDebugFunc(self.getMessage('ajaxDebugResponse',objText.responseText));}self.fetchingMark.className=Zapatec.Form.IGNORE_CLASSNAME+" zpNotFetching";if(objText.responseText==null){Zapatec.Log({description:self.getMessage('ajaxFillNoResponseError',objText.responseText)});return null;}var objResponse=Zapatec.Transport.parseJson({strJson:objText.responseText});if(objResponse==null){Zapatec.Log({description:self.getMessage('ajaxFillCantParseError',objText.responseText)});return null;}if(!objResponse.success){self.ajaxError=typeof(objResponse.generalError)!='string'||objResponse.generalError.length==0?self.getMessage('ajaxFillGeneralError'):objResponse.generalError;}else{self.ajaxError=null;var formObject=self.form;var fillData=objResponse.fillData;if(fillData.length==0){return null;}else{var fields=fillData[0];for(var ii=0;ii<fields.length;ii++){var field=formObject.container.elements[fields[ii]['fieldName']];if(!field){continue;}Zapatec.Form.Utils.setValue(field,fields[ii]['fieldValue']);if(field.zpFormField){field.zpFormField.setValueFromField(true);}}}}self.validate();},onError:function(objError){var strError='';if(objError.errorCode){strError+=objError.errorCode+' ';}strError+=objError.errorDescription;self.fetchingMark.className=Zapatec.Form.IGNORE_CLASSNAME+" zpNotFetching";alert(strError);self.ajaxError=null;if(self.config.formConfig.ajaxDebugFunc){self.config.formConfig.ajaxDebugFunc(self.getMessage('ajaxDebugResponseError',strError));}}});};Zapatec.Form.Field.prototype.suggestValue=function(showAll){if(!this.hasFeature("zpFormSuggest")||!showAll&&this.isEmpty()){return null;}var suggestUrl=this.getFeature("zpFormSuggest");var suggestMethod=this.getFeature("zpFormSuggestMethod");var suggestParam=this.getFeature("zpFormSuggestParam");var suggestQuery=this.getFeature("zpFormSuggestQuery");if(typeof(suggestMethod)!='string'){suggestMethod="GET";}if(typeof(suggestParam)!='string'){suggestParam=this.field.name;}if(typeof(suggestQuery)!='string'){suggestQuery="";}suggestQuery+="&"+escape(suggestParam)+"="+(showAll?"":escape(this.getValue()));if(suggestUrl.indexOf("?")<0){suggestUrl+="?";}suggestUrl+="&"+Math.random();if(suggestMethod=='GET'){suggestUrl+="&"+suggestQuery;}this.fetchingMark.className="zpIsFetching "+Zapatec.Form.IGNORE_CLASSNAME;var self=this;if(this.config.formConfig.ajaxDebugFunc){this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugSeparator'));this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugSuggestTitle',this.field.name));this.config.formConfig.ajaxDebugFunc(suggestMethod+" "+suggestUrl);this.config.formConfig.ajaxDebugFunc(this.getMessage('ajaxDebugQuery',("GET"?"":suggestQuery)));}Zapatec.Transport.fetch({url:suggestUrl,content:suggestMethod=="GET"?null:suggestQuery,method:suggestMethod,onLoad:function(objText){if(self.config.formConfig.ajaxDebugFunc){self.config.formConfig.ajaxDebugFunc(self.getMessage('ajaxDebugResponse',objText.responseText));}self.fetchingMark.className=Zapatec.Form.IGNORE_CLASSNAME+" zpNotFetching";if(objText.responseText==null){Zapatec.Log({description:self.getMessage('ajaxSuggestNoResponseError',objText.responseText)});return null;}var objResponse=Zapatec.Transport.parseJson({strJson:objText.responseText});if(objResponse==null){Zapatec.Log({description:self.getMessage('ajaxSuggestCantParseError',objText.responseText)});return null;}if(!objResponse.success){alert(typeof(objResponse.generalError)!='string'||objResponse.generalError.length==0?self.getMessage('ajaxSuggestGeneralError'):objResponse.generalError);}else{self.autoCompleteValue(objResponse);}self.validate();},onError:function(objError){var strError='';if(objError.errorCode){strError+=objError.errorCode+' ';}strError+=objError.errorDescription;self.fetchingMark.className=Zapatec.Form.IGNORE_CLASSNAME+" zpNotFetching";Zapatec.Log({description:strError});if(self.config.formConfig.ajaxDebugFunc){self.config.formConfig.ajaxDebugFunc(self.getMessage('ajaxDebugResponseError',strError));}}});};Zapatec.Form.Field.prototype.getAutoCompleteOptions=function(showAll){var opts={body:[]};var currVal=this.getValue();if(this.hasFeature("zpFormAutoComplete")||this.hasFeature("zpFormAutoCompleteStrict")){for(var ii=0;ii<this.autoCompleteOptions.length;ii++){if((this.hasFeature("zpFormAutoCompleteStrict")?this.autoCompleteOptions[ii].substring(0,currVal.length):this.autoCompleteOptions[ii].substring(0,currVal.length).toLowerCase())==(this.hasFeature("zpFormAutoCompleteStrict")?currVal:currVal.toLowerCase())||showAll){opts.body.push([this.autoCompleteOptions[ii]]);}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -