当前位置: 首页 > news >正文

在UltraWebGrid中验证填入数据

官方例子:


Summary It may prove beneficial to validate user input within the client-side events. The BeforeExitEditModeHandler allows for a perfect time to validate the the input and "lock" the user on the cell until proper data has been entered. Additional Information First, add a handler for the client-side event, BeforeExitEditModeHandler. This property can be set either in the Property Pages under displaylayout>ClientsideEvents>BeforeExitEditModeHandler or in code: UltraWebGrid1.DisplayLayout.ClientSideEvents.BeforeExitEditModeHandler = "BeforeExitEditMode" This event receives two parameters: gridname and cell id. To keep the user within the cell, return true to cancel the event. Here is a sample that will not allow a user to enter a date that is after today for a birthdate: //create a global variable so alertbox does not appear twice. box appears twice since in the BeforeEndEditMode you are calling alert(message) which tries to end the edit as well //without this then you would find yourself in an infinite loop or have an alert appear twice. var oldvalue=null; function beforeExitEditMode(gridName,cellID) { //get the cell cell=igtbl_getCellById(cellID); //get the grid grid=igtbl_getGridById(gridName); //check to see if the user is in the birthdate column if(cell.Column.Key=="BirthDate") { //get today's date var today=new Date(); //get the value of the current cell var valDate=new Date(cell.getValue()); if(valDate < today) { //if the date is before today then allow them to exit edit mode return 0; } //won't get here unless date is greater then today since a valid date would have exited the function above //the next line is neccesarry so we know that this is the first time the user is coming through the function and //we avoid duplicate alert messages if(oldvalue==null) { //set oldvalue to current value so this is not hit next time through and display alert box oldvalue=valDate; alert("BirthDate can't be in the future"); } //if the user has gotten this far then value is invlaid so return 1 to cancel the exiting of edit mode return 1; } }


我自己写的,感觉写的不太优雅,比较丑陋,但是照着官方的写总是满足不了需求

var oldVal function Grid_BeforeExitEditModeHandler(gridName, cellID) { //get the cell cell = igtbl_getCellById(cellID); //get the grid grid = igtbl_getGridById(gridName); if (cell.Column.Key == "operatingtimeperday") { oldVal = parseFloat(cell.getValue()); } } function Grid_AfterExitEditModeHandler(gridName, cellID) { //get the cell cell = igtbl_getCellById(cellID); //get the grid grid = igtbl_getGridById(gridName); //check to see if the user is in the birthdate column if (cell.Column.Key == "operatingtimeperday") { //get the value of the current cell var val = parseFloat(cell.getValue()); if (val > 24) { alert("输入时间不可大于24小时"); cell.setValue(oldVal); return 1; } if (val < 24) { return 0; } } }

相关文章:

  • HTML5 拖拽图片到网页内
  • HTML5批量拖拽图片到网页
  • [创业] 美国硅谷风险投资行业的详细报告(2008年第四季度)
  • C# 异步调用代理类
  • C#事件和委托的基础知识模型
  • 异步发送HTTP请求
  • Flex开发流程设计器的经验之谈(2)
  • html5 涂鸦板
  • [IE编程] IE中使网页元素进入编辑模式
  • linux命令练习 笔记
  • [IE技巧] IE 中打开Office文件的设置
  • 配置系统未能初始化 错误的解决方案
  • [IE编程] IE中对网页进行截图的编程接口
  • c# 反射 遍历实体的所有字段,ObjectDumper类实现
  • Flex开发流程设计器的经验之谈(3)
  • css选择器
  • JavaScript中的对象个人分享
  • MYSQL 的 IF 函数
  • PAT A1120
  • Promise面试题2实现异步串行执行
  • WordPress 获取当前文章下的所有附件/获取指定ID文章的附件(图片、文件、视频)...
  • 百度地图API标注+时间轴组件
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 面试遇到的一些题
  • 如何胜任知名企业的商业数据分析师?
  • 如何在 Tornado 中实现 Middleware
  • 实战|智能家居行业移动应用性能分析
  • 自动记录MySQL慢查询快照脚本
  • ​猴子吃桃问题:每天都吃了前一天剩下的一半多一个。
  • ​业务双活的数据切换思路设计(下)
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (力扣)1314.矩阵区域和
  • (力扣)循环队列的实现与详解(C语言)
  • (生成器)yield与(迭代器)generator
  • (五)关系数据库标准语言SQL
  • (一)u-boot-nand.bin的下载
  • (转)MVC3 类型“System.Web.Mvc.ModelClientValidationRule”同时存在
  • .NET Core MongoDB数据仓储和工作单元模式封装
  • .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
  • .NET 反射 Reflect
  • .Net 访问电子邮箱-LumiSoft.Net,好用
  • .NET/C# 获取一个正在运行的进程的命令行参数
  • .NET6 命令行启动及发布单个Exe文件
  • /usr/bin/env: node: No such file or directory
  • [ vulhub漏洞复现篇 ] Grafana任意文件读取漏洞CVE-2021-43798
  • [Android Pro] Notification的使用
  • [Android]使用Android打包Unity工程
  • [AX]AX2012 SSRS报表Drill through action
  • [Codeforces1137D]Cooperative Game
  • [DevEpxress]GridControl 显示Gif动画
  • [Editor]Unity Editor类常用方法
  • [EFI]Dell Latitude-7400电脑 Hackintosh 黑苹果efi引导文件
  • [E单调栈] lc2487. 从链表中移除节点(单调栈+递归+反转链表+多思路)
  • [ffmpeg] x264 配置参数解析
  • [Hibernate] - Fetching strategies