ext 扩展控件—moneyField
/**
*数字控件
*带大写提示,和千分位
**/
Ext.define(appNameSpace+'.utils.MoneyField', {
extend : 'Ext.form.field.Text',
alias : 'widget.moneyfield',
initComponent : function() {
var me = this;
Ext.apply(Ext.form.field.VTypes, {
regexMoney: function(val, field) {
val = val.replace(/,/g,'');
if(isNaN(Number(val))){
if(field.negative_Text && val.indexOf("-")== 0 && val.replace(/-/g,"").length == val.length-1){
return true
}else{
return false;
}
}else{
return true;
}
},
regexMoneyText: "请输入数字,最大保留两位小数!"
});
me.on('keypress',function(t,e){
if(t.value.indexOf(".") != -1 && e.keyCode == 46){
e.stopEvent();
}
if((!t.negative_Text) && (44>e.keyCode && e.keyCode>58)){
e.stopEvent();
}else if((t.negative_Text) && (45>e.keyCode && e.keyCode>58)){
e.stopEvent();
} });
me.on("mouseover",function(){console.log("123")})
// Ext.apply(me,{});
this.callParent(arguments); // 调用你模块的initComponent函数
},
baseChars: '0123456789.-',
maskRe :new RegExp('[-0-9\.]'),
fieldStyle:"text-align:right;",
enableKeyEvents:true,
cursor:null,
vtype:"regexMoney",
getTip: function() {
var tip = this.tip;
if (!tip) {
tip = this.tip = Ext.widget('tooltip', {
target: this.el,
width: 420,
autoHide: false,
anchor: 'top',
//closable: true,
mouseOffset: [100, -2],
constrainPosition: false
});
tip.show();
}
return tip;
},
getValue: function(flag) {
var me = this,
val = me.rawToValue(me.processRawValue(me.getRawValue()));
// me.value = val;
if(!flag){
val = val.replace(/,/g,'');
}
return val;
},
onChange:function(newVal, oldVal){
/*if(value.replace(/,/g,'') == oldVal.replace(/,/g,'')){
if(newVal.length < oldVal.length){
for(var i=0;i<oldVal.length;i++){
if(newVal[i] != oldVal[i]){
this.setValue(this.toThousands(value));
}
}
}else{
return;
}
}*/
var t = this;
if(isNaN(Number(newVal.replace(/,/g,'')))){
if(t.negative_Text && newVal.indexOf("-")==0 && newVal.replace(/-/g,"").length == newVal.length-1){
return
}else{
this.setValue("");
return;
}
}
if(!t.isValid()){
return;
}
var el = this.inputEl.dom;
/**数字大写**/
if(newVal==oldVal){
return;
}
var decimal = "";
var value = newVal;
/*if(newVal.indexOf(".") != -1){
if(newVal.substring(value.indexOf(".")+1).indexOf(".") != -1){
this.setValue(oldVal);
return;
}
}*/
if(newVal.indexOf(",") != -1){
value = newVal.replace(/,/g,'');
if(newVal.replace(/,/g,'') == oldVal.replace(/,/g,'')){
return;
}
} var tip = this.getTip();
t.setValue(t.getValue(true).replace(/\s/g, ""));
t.setValue(t.getValue(true).replace(/。/g, "."));
if(t.value != null && t.value != ''){
tip.setDisabled(false);
tip.setTitle(atoc(value));
tip.show();
}else{
tip.setDisabled(true);
tip.hide();
}
/**千分位**/
if(newVal == ""){
return;
} if(value.indexOf(".") != -1){
var valLength = value.substring(value.indexOf(".")).length;
if(valLength == 1){
decimal = ".";
}else{
decimal = value.substring(value.indexOf("."));
}
value = value.substring("0",value.indexOf("."));
}
var n_ = "";
if(this.negative_Text && value.indexOf("-")==0){
value = value.replace(/-/g,'');
n_ = "-"
}
this.setValue(n_ + this.toThousands(value,newVal)+decimal);
el.setSelectionRange(this.cursor,this.cursor);
return;
},
onBlur:function(e){
var me = this;
if(!me.isValid()){
return;
}
var val = me.getValue(true);
/**数字大写**/
var tip = this.getTip();
tip.setDisabled(true);
tip.hide();
/**小数位**/
var value = val.replace(/,/g,'');
if(val.indexOf(".") != -1){
value = parseFloat(value).toFixed(2);
var sVal = val.substring(0,val.indexOf("."));
var eVal = value.substring(value.indexOf("."));
var n_ = "";
if(this.negative_Text && value.indexOf("-")==0){
value = value.replace(/-/g,'');
n_ = "-"
}
me.setValue(n_ + this.toThousands(sVal)+eVal);
}else{
if(val != ""){
me.setValue(this.toThousands(value));
}
}
return;
},
onFocus:function(e){
var me = this;
var el = this.inputEl.dom;
el.setAttribute("onpaste","return false");
var val = me.getValue(true);
var newVal = val;
/**数字大写**/
var t = this;
if(!t.isValid()){
return;
}
var tip = this.getTip();
t.newVal = t.value;
t.setValue(t.getValue(true).replace(/\s/g, ""));
t.setValue(t.getValue(true).replace(/。/g, "."));
if(t.value != null && t.value != ''){
tip.setDisabled(false);
tip.setTitle(atoc(newVal));
tip.show();
}else{
tip.setDisabled(true);
tip.hide();
}
me.getValue(true);
return;
},
toThousands:function(num,val) {
var el = this.inputEl.dom;
var value = this.value;
if(num.indexOf(",") != -1){
num = num.replace(/,/g,'');
}
var str = el.selectionStart;
var num = (num || 0).toString(), result = '';
while (num.length > 3) {
result = ',' + num.slice(-3) + result;
num = num.slice(0, num.length - 3);
}
if (num) { result = num + result; }
//光标在最后的时候
if(str == value.length && value.indexOf(".")==-1){
this.cursor = result.length;
}else if((result.length - value.length == 1 && value.indexOf(".")==-1)||(result.length - value.substring(0,value.indexOf(".")).length==1 && value.indexOf(".") !=-1)){
this.cursor = str+1;
}else if(result.length - value.length == -1 && value.indexOf(".")==-1||(result.length - value.substring(0,value.indexOf(".")).length==-1 && value.indexOf(".") !=-1)){
this.cursor = str-1;
}else if(result.length == value.length && value.indexOf(".")==-1){
this.cursor = str;
}else if(str == value.length && value.indexOf(".") !=-1){
this.cursor = value.length;
}else if(value.indexOf(".") !=-1 ){
this.cursor = str;
}
if(this.negative_Text && value.indexOf("-")==0){
this.cursor = this.cursor+1
}
/*if(str == val.length &&val.indexOf(".") == -1){
this.cursor = result.length;
}else if(str == val.length &&val.indexOf(".") != -1){
var num = val.substring(val.indexOf(".")).length;
this.cursor = result.length + num;
}else if(str == this.value.length){
this.cursor = str;
}*/
return result;
}
});
ext 扩展控件—moneyField的更多相关文章
- 多年前写的文本框扩展控件(有ValueChanging事件等),已放github
本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 阅读目录 介绍 起因 代码 使用 GitHub ...
- JavaFX的扩展控件库ControlsFX介绍
声明: 本博客文章原创类别的均为个人原创,版权所有.转载请注明出处: http://blog.csdn.net/ml3947,另外本人的个人博客:http://www.wjfxgame.com. ...
- WPF自定义控件(三)の扩展控件
扩展控件,顾名思义就是对已有的控件进行扩展,一般继承于已有的原生控件,不排除继承于自定义的控件,不过这样做意义不大,因为既然都自定义了,为什么不一步到位呢,有些不同的需求也可以通过此来完成,不过类似于 ...
- 2.C#Panel扩展控件
1.解决方案下添加新建项目新建类库 2. 在项目下添加新建项选择新建组件类 3.先引用,然后导入两个命名空间 4.因为是扩展控件,把继承自Component改成继承自Panel using Syste ...
- 验证控件插图扩展控件ValidatorCalloutExtender(用于扩展验证控件)和TextBoxWatermarkExtender
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptMan ...
- Ext.net控件调整后台事件、方法论
一.以ext.net的button为例调用后台事件: 前台代码: <ext:Button ID="Button1" runat="server" Text ...
- Ext表格控件
表格控件其实也就是帮我们完成了数据的填充工作而已,具体的数据源.要显示的列,列的定制.数据源中的哪条数据显示在哪个列中等属性还是需要我们自己手动配置的,所以我们分下面几步来完成网格控件的数据绑定: 1 ...
- IExtenderProvider,c#组件扩展控件属性
[ProvideProperty("IsEnabled", typeof(LayoutControlItem)), ToolboxItemFilter("System.W ...
- QGEditors.WinForms WinForms下使用的部分扩展控件
Nuget: https://www.nuget.org/packages/QGEditors.WinForms/ PM> Install-Package QGEditors.WinForms ...
随机推荐
- javascript获取选中的文本/html
首先来谈一下Selection对象和Range对象. Selection是window.getSelection()方法返回的一个对象,用于表示用户选中的文本区域.Selection对象表现为一组Ra ...
- 基于url的权限管理
基于url权限管理流程 完成权限管理的数据模型创建. 1. 系统登陆 系统 登陆相当 于用户身份认证,用户成功,要在session中记录用户的身份信息. 操作流程: 用户进行登陆页面 输入用户 ...
- Java多线程编程的常见陷阱(转)
Java多线程编程的常见陷阱 2009-06-16 13:48 killme2008 blogjava 字号:T | T 本文介绍了Java多线程编程中的常见陷阱,如在构造函数中启动线程,不完全的同步 ...
- Day 4 @ RSA Conference Asia Pacific & Japan 2016
09.00 – 09.45 hrs Advanced Malware and the Cloud: The New Concept of 'Attack Fan-out' Krishna Naraya ...
- 支持“***Context”上下文的模型已在数据库创建后发生更改。请考虑使用 Code First 迁移更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269)。
在用VS进行MVC开发的过程中遇到如下问题: 支持“***Context”上下文的模型已在数据库创建后发生更改.请考虑使用 Code First 迁移更新数据库(http://go.microsoft ...
- 晕,hibernate 的 merge和cascade="all-delete-orphan"要慎重合在一起使用
遇到一个比较后悔莫及事情,使用了hibernate 的 merge和cascade="all-delete-orphan" ,子表数据被删除了. 1.使用cascade=" ...
- [WebGL入门]十四,绘制多边形
注意:文章翻译http://wgld.org/.原作者杉本雅広(doxas),文章中假设有我的额外说明,我会加上[lufy:].另外,鄙人webgl研究还不够深入.一些专业词语,假设翻译有误,欢迎大家 ...
- MFC程序实现给对话框加入�背景图片
1.插入一个Bitmap的资源图片,如果资源名称为:IDC_BITMAP1 2.在CXXXDialog::OnPaint()中实现: void CMyDialogDlg::OnPaint() { if ...
- 设计模式——工厂模式 (C++实现)
软件领域中的设计模式为开发人员提供了一种使用专家设计经验的有效途径.设计模式中运用了面向对象编程语言的重要特性:封装.继承.多态,真正领悟设计模式的精髓是可能一个漫长的过程,需要大量实践经验的积累. ...
- apache目录及文件讲解
apache目录下bin,conf,htdocs,logs,modules讲解 bin: ab 压力测试工具 apachectl 启动命令 apxs ...