KDTextField.htc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <!--/******************************************************************
  2. ** 文件名: KDTextField.htc
  3. ** Copyright (c) 2005 金蝶国际软件集团有限公司 研发中心
  4. ** http://www.kingdee.com
  5. **
  6. ** 创建人: 叶汉良
  7. ** 日 期: 2005.06.13
  8. **
  9. ** 描述:单行文本输入控件
  10. ** 版 本:Web V1.0
  11. ******************************************************************/-->
  12. <public:component tagName="KDTextField" lightWeight=true>
  13. <public:attach event="oncontentready" onevent="kdTextFieldReady()" />
  14. <public:attach event="onpropertychange" onevent="kdTextFieldPropertyChange()"/>
  15. <public:event name="onEvtClick" id = "evtClick">
  16. <public:event name="onEvtMouseDown" id = "evtMouseDown">
  17. <public:event name="onEvtMouseUp" id = "evtMouseUp">
  18. <public:event name="onEvtMouseOver" id = "evtMouseOver">
  19. <public:event name="onEvtMouseOut" id = "evtMouseOut">
  20. <public:event name="onEvtMouseMove" id = "evtMouseMove">
  21. <public:event name="onEvtFocus" id = "evtFocus">
  22. <public:event name="onEvtBlur" id = "evtBlur">
  23. <public:event name="onEvtKeyDown" id = "evtKeyDown">
  24. <public:event name="onEvtKeyUp" id = "evtKeyUp">
  25. <public:event name="onEvtKeyPress" id = "evtKeyPress">
  26. <public:event name="onEvtChange" id = "evtChange">
  27. <public:event name="onEvtBeforePaste" id = "evtBeforePaste">
  28. <public:property name="initializeBorderColor" value="#B4B4B4"/>
  29. <public:property name="initializeBGColor" value="#FFFFFF"/>
  30. <public:property name="initializeTextFontColor" value="#000000"/>
  31. <public:property name="focusBorderColor" value="#5C85B3"/>
  32. <public:property name="focusBGColor" value="#F9F9F9"/>
  33. <public:property name="focusTextFontColor" value="#000000"/>
  34. <public:property name="readonlyBorderColor" value="#B4B4B4"/>
  35. <public:property name="readonlyBGColor" value="#FFFFFF"/>
  36. <public:property name="readonlyTextFontColor" value="#777777"/>
  37. <public:property name="disableBorderColor" value="#B4B4B4"/>
  38. <public:property name="disableBGColor" value="#D9D9D0"/>
  39. <public:property name="disableTextFontColor" value="#777777"/>
  40. <public:property name="mustBorderColor" value="#B4B4B4"/>
  41. <public:property name="mustBGColor" value="#FCFBCE"/>
  42. <public:property name="mustTextFontColor" value="#000000"/>
  43. <public:property name="width" value="170"/>
  44. <public:property name="height" value="19"/>
  45. <public:property name="readonly" value="false"/>
  46. <public:property name="disable" value="false"/>
  47. <public:property name="name" value=""/>
  48. <public:property name="value" get="getValue" put="putValue"/>
  49. <public:property name="IDName" value=""/>
  50. <public:property name="IDValue" value=""/>
  51. <public:property name="maxLength" value=""/>
  52. <public:property name="fontSize1" value="9pt"/>
  53. <public:property name="fontFamily1" value="arial"/>
  54. <public:property name="dataType" value=""/>
  55. <public:property name="tabIndex1" value=""/>
  56. <public:property name="tips" value=""/>
  57. <public:property name="mustInput" value="false"/>
  58. <public:property name="mustInputMsg" value=""/>
  59. <public:property name="align" value="left"/>
  60. <public:property name="enter2tab" value="true"/>
  61. <public:method name="focus"/>
  62. </public:component>
  63. <script language="javascript">
  64. var sValue = "";
  65. /**
  66. *初始化处理的相关内容
  67. *
  68. */
  69. function kdTextFieldReady()
  70. {
  71. element.innerHTML = "<input type='text'/><input type='hidden'>";
  72. initCss();
  73. var oInputE = element.children(0);
  74. var oStyle = oInputE.style;
  75. oStyle.paddingLeft = 3;
  76. oStyle.width = width;
  77. oStyle.height = height;
  78. if (height >= 19)
  79. {
  80. oStyle.paddingTop = 2 + (parseInt(height) - 19) / 5;
  81. }
  82. else
  83. {
  84. oStyle.paddingTop = 0;
  85. }
  86. oStyle.borderStyle = "solid";
  87. oStyle.borderWidth = 1;
  88. oInputE.value = sValue;
  89. oStyle.fontFamily = fontFamily1;
  90. oStyle.fontSize = fontSize1;
  91. oInputE.name = name;
  92. oInputE.title = tips;
  93. oStyle.textAlign = align;
  94. if (maxLength != null && maxLength != "")
  95. {
  96. element.children(0).maxLength = maxLength;
  97. }
  98. //不可用状态
  99. if (eval(disable) == true)
  100. {
  101. oStyle.borderColor = disableBorderColor;
  102. oStyle.backgroundColor = disableBGColor;
  103. oStyle.color = disableTextFontColor;
  104. //此处不使用disabled这个属性,否则文字的颜色无法进行修改
  105. oInputE.readOnly = true;
  106. oInputE.tabIndex = "";
  107. }
  108. else
  109. {
  110. //只读状态
  111. if (eval(readonly) == true)
  112. {
  113. oStyle.borderColor = readonlyBorderColor;
  114. oStyle.backgroundColor = readonlyBGColor;
  115. oStyle.color = readonlyTextFontColor;
  116. oInputE.readOnly = true;
  117. }
  118. //必录项
  119. else if (eval(mustInput) == true)
  120. {
  121. oStyle.borderColor = mustBorderColor;
  122. oStyle.backgroundColor = mustBGColor;
  123. oStyle.color = mustTextFontColor;
  124. }
  125. else
  126. {
  127. oStyle.borderColor = initializeBorderColor;
  128. oStyle.backgroundColor = initializeBGColor;
  129. oStyle.color = initializeTextFontColor;
  130. }
  131. oInputE.tabIndex = tabIndex1;
  132. }
  133. element.children(1).name = IDName;
  134. element.children(1).value = IDValue;
  135. oInputE.attachEvent("onclick",function(){execute("click")});
  136. oInputE.attachEvent("onmousedown",function(){execute("mousedown")});
  137. oInputE.attachEvent("onmouseover",function(){execute("mouseover")});
  138. oInputE.attachEvent("onmouseout",function(){execute("mouseout")});
  139. oInputE.attachEvent("onmouseup",function(){execute("mouseup")});
  140. oInputE.attachEvent("onmousemove",function(){execute("mousemove")});
  141. oInputE.attachEvent("onfocus",function(){execute("focus")});
  142. oInputE.attachEvent("onblur",function(){execute("blur")});
  143. oInputE.attachEvent("onkeypress",function(){return execute("keypress");});
  144. oInputE.attachEvent("onkeydown",function(){execute("keydown")});
  145. oInputE.attachEvent("onkeyup",function(){execute("keyup")});
  146. oInputE.attachEvent("onchange",function(){execute("change")});
  147. oInputE.attachEvent("onbeforepaste",function(){return execute("beforepaste");});
  148. oInputE.attachEvent("onselectstart",function(){return execute("selectstart");});
  149. }
  150. /**
  151. *属性改变时相关的属性设置
  152. *
  153. */
  154. function kdTextFieldPropertyChange()
  155. {
  156. if (element.initcssing == true)
  157. {
  158. return;
  159. }
  160. var oStyle = element.children(0).style;
  161. switch(event.propertyName.toString().toLowerCase())
  162. {
  163. case "width":
  164. {
  165. oStyle.width = width;
  166. break;
  167. }
  168. case "height":
  169. {
  170. oStyle.height = height;
  171. break;
  172. }
  173. //初始化颜色发生了变化
  174. case "initializebordercolor":
  175. {
  176. if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
  177. {
  178. oStyle.borderColor = initializeBorderColor;
  179. }
  180. break;
  181. }
  182. case "initializebgcolor":
  183. {
  184. if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
  185. {
  186. oStyle.backgroundColor = initializeBGColor;
  187. }
  188. break;
  189. }
  190. case "initializetextfontcolor":
  191. {
  192. if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
  193. {
  194. oStyle.color = initializeTextFontColor;
  195. }
  196. break;
  197. }
  198. //只读颜色发生了变化
  199. case "readonlybordercolor":
  200. {
  201. if (eval(disable) != true && eval(readonly) == true)
  202. {
  203. oStyle.borderColor = readonlyBorderColor;
  204. }
  205. break;
  206. }
  207. case "readonlybgcolor":
  208. {
  209. if (eval(disable) != true && eval(readonly) == true)
  210. {
  211. oStyle.backgroundColor = readonlyBGColor;
  212. }
  213. break;
  214. }
  215. case "readonlytextfontcolor":
  216. {
  217. if (eval(disable) != true && eval(readonly) == true)
  218. {
  219. oStyle.color = readonlyTextFontColor;
  220. }
  221. break;
  222. }
  223. //disable的时候颜色发生了变化
  224. case "disablebordercolor":
  225. {
  226. if (eval(disable) == true)
  227. {
  228. oStyle.borderColor = disableBorderColor;
  229. }
  230. break;
  231. }
  232. case "disablebgcolor":
  233. {
  234. if (eval(disable) == true)
  235. {
  236. oStyle.backgroundColor = disableBGColor;
  237. }
  238. break;
  239. }
  240. case "disabletextfontcolor":
  241. {
  242. if (eval(disable) == true)
  243. {
  244. oStyle.color = disableTextFontColor;
  245. }
  246. break;
  247. }
  248. //只读发生了变化
  249. case "readonly":
  250. {
  251. if (eval(disable) != true)
  252. {
  253. //变化为只读状态
  254. if (eval(readonly) == true)
  255. {
  256. oStyle.borderColor = readonlyBorderColor;
  257. oStyle.backgroundColor = readonlyBGColor;
  258. oStyle.color = readonlyTextFontColor;
  259. element.children(0).readOnly = true;
  260. }
  261. else
  262. {
  263. if (eval(mustInput) == true)
  264. {
  265. oStyle.borderColor = initializeBorderColor;
  266. oStyle.backgroundColor = initializeBGColor;
  267. oStyle.color = initializeTextFontColor;
  268. }
  269. else
  270. {
  271. oStyle.borderColor = mustBorderColor;
  272. oStyle.backgroundColor = mustBGColor;
  273. oStyle.color = mustTextFontColor;
  274. }
  275. element.children(0).readOnly = false;
  276. }
  277. }
  278. break;
  279. }
  280. //不可使用发生了变化
  281. case "disable":
  282. {
  283. if (eval(disable) == true)
  284. {
  285. oStyle.borderColor = disableBorderColor;
  286. oStyle.backgroundColor = disableBGColor;
  287. oStyle.color = disableTextFontColor;
  288. element.children(0).readOnly = true;
  289. element.children(0).tabIndex = "";
  290. }
  291. else
  292. {
  293. if (eval(readonly) == true)
  294. {
  295. oStyle.borderColor = readonlyBorderColor;
  296. oStyle.backgroundColor = readonlyBGColor;
  297. oStyle.color = readonlyTextFontColor;
  298. element.children(0).readOnly = true;
  299. }
  300. else
  301. {
  302. if (eval(mustInput) == false)
  303. {
  304. oStyle.borderColor = initializeBorderColor;
  305. oStyle.backgroundColor = initializeBGColor;
  306. oStyle.color = initializeTextFontColor;
  307. }
  308. else
  309. {
  310. oStyle.borderColor = mustBorderColor;
  311. oStyle.backgroundColor = mustBGColor;
  312. oStyle.color = mustTextFontColor;
  313. }
  314. element.children(0).readOnly = false;
  315. }
  316. if (tabIndex1 != "")
  317. {
  318. element.children(0).tabIndex = tabIndex1;
  319. }
  320. }
  321. break;
  322. }
  323. case "fontsize1":
  324. {
  325. oStyle.fontSize = fontSize1;
  326. break;
  327. }
  328. case "tips":
  329. {
  330. element.children(0).title = tips;
  331. break;
  332. }
  333. default:
  334. break;
  335. }
  336. }
  337. /**
  338. *处理相关事件
  339. *
  340. */
  341. function execute(sEvent)
  342. {
  343. //不可处理状态下,不能进行处理
  344. if (eval(disable) == true)
  345. {
  346. return false;
  347. }
  348. var evt = window.document.createEventObject(event);
  349. if (sEvent == "click")
  350. {
  351. evtClick.fire(evt);
  352. }
  353. else if (sEvent == "mouseup")
  354. {
  355. evtMouseUp.fire(evt);
  356. }
  357. else if (sEvent == "mousedown")
  358. {
  359. element.isMouseDown = true;
  360. evtMouseDown.fire(evt);
  361. }
  362. else if (sEvent == "mousemove")
  363. {
  364. evtMouseMove.fire(evt);
  365. }
  366. else if (sEvent == "mouseover")
  367. {
  368. evtMouseOver.fire(evt);
  369. }
  370. else if (sEvent == "mouseout")
  371. {
  372. evtMouseOut.fire(evt);
  373. }
  374. else if (sEvent == "keyup")
  375. {
  376. evtKeyUp.fire(evt);
  377. }
  378. else if (sEvent == "keydown")
  379. {
  380. doKeyDown(evt);
  381. }
  382. else if (sEvent == "keypress")
  383. {
  384. evtKeyPress.fire(evt);
  385. }
  386. else if (sEvent == "change")
  387. {
  388. evtChange.fire(evt);
  389. }
  390. else if (sEvent == "beforepaste")
  391. {
  392. return doBeforePaste(evt);
  393. }
  394. else if (sEvent == "selectstart")
  395. {
  396. return doSelectStart(evt);
  397. }
  398. //可编辑状态下,可以修改边框的相关的颜色
  399. if (eval(readonly) != true)
  400. {
  401. if (sEvent == "focus")
  402. {
  403. doFocus(evt);
  404. }
  405. else if (sEvent == "blur")
  406. {
  407. if (eval(mustInput) == true)
  408. {
  409. element.children(0).style.borderColor = mustBorderColor;
  410. element.children(0).style.backgroundColor = mustBGColor;
  411. element.children(0).style.color = mustTextFontColor;
  412. if (element.children(0).value == "" && mustInputMsg != "")
  413. {
  414. alert(mustInputMsg);
  415. }
  416. }
  417. else
  418. {
  419. element.children(0).style.borderColor = initializeBorderColor;
  420. element.children(0).style.backgroundColor = initializeBGColor;
  421. element.children(0).style.color = initializeTextFontColor;
  422. }
  423. evtBlur.fire(evt);
  424. }
  425. }
  426. }
  427. /**
  428. *得到焦点
  429. *
  430. */
  431. function focus()
  432. {
  433. if (eval(disable) == true)
  434. {
  435. return;
  436. }
  437. element.children(0).focus();
  438. }
  439. /**
  440. *选择部分的时候修改显示的颜色
  441. *
  442. */
  443. function doSelectStart()
  444. {
  445. if (eval(disable) == true)
  446. {
  447. return false;
  448. }
  449. }
  450. /**
  451. *处理keyDown事件,主要按下enter键的时候,类似tab键按下
  452. *
  453. */
  454. function doKeyDown(evt)
  455. {
  456. if (event.keyCode == 13 && eval(enter2tab) == true)
  457. {
  458. evtKeyDown.fire(evt);
  459. event.keyCode = 9;
  460. return;
  461. }
  462. evtKeyDown.fire(evt);
  463. }
  464. /**
  465. *处理beforePaste事件,如果设置了maxlength的时候,不能随意粘贴
  466. *
  467. */
  468. function doBeforePaste(evt)
  469. {
  470.   evtBeforePaste.fire(evt);
  471. return true;
  472. }
  473. /**
  474. *处理focus事件
  475. *
  476. */
  477. function doFocus(evt)
  478. {
  479. var oStyle = element.children(0).style;
  480. if (eval(mustInput) == false)
  481. {
  482. oStyle.borderColor = focusBorderColor;
  483. oStyle.backgroundColor = focusBGColor;
  484. oStyle.color = focusTextFontColor;
  485. }
  486. else
  487. {
  488. oStyle.borderColor = focusBorderColor;
  489. oStyle.backgroundColor = mustBGColor;
  490. oStyle.color = focusTextFontColor;
  491. }
  492. if (element.isMouseDown != true)
  493. {
  494. element.children(0).select();
  495. }
  496. element.isMouseDown = false;
  497. evtFocus.fire(evt);
  498. }
  499. /**
  500. *得到控件的值
  501. *
  502. */
  503. function getValue()
  504. {
  505. return element.children(0).value;
  506. }
  507. /**
  508. *设置控件的值
  509. *
  510. */
  511. function putValue(sValue1)
  512. {
  513. if (!element.children(0))
  514. {
  515. sValue = sValue1;
  516. }
  517. else
  518. {
  519. sValue = sValue1;
  520. element.children(0).value = sValue;
  521. }
  522. }
  523. /**
  524. *初始样式
  525. *
  526. */
  527. function initCss()
  528. {
  529. element.initcssing = true;
  530. var os = element.currentStyle;
  531. initializeBorderColor = getCssStyle(initializeBorderColor,"#B4B4B4",os.initializeBorderColor);
  532. initializeBGColor = getCssStyle(initializeBGColor,"#FFFFFF",os.initializeBGColor);
  533. initializeTextFontColor = getCssStyle(initializeTextFontColor,"#000000",os.initializeTextFontColor);
  534. focusBorderColor = getCssStyle(focusBorderColor,"#5C85B3",os.focusBorderColor);
  535. focusBGColor = getCssStyle(focusBGColor,"#F9F9F9",os.focusBGColor);
  536. focusTextFontColor = getCssStyle(focusTextFontColor,"#000000",os.focusTextFontColor);
  537. readonlyBorderColor = getCssStyle(readonlyBorderColor,"#B4B4B4",os.readonlyBorderColor);
  538. readonlyBGColor = getCssStyle(readonlyBGColor,"#FFFFFF",os.readonlyBGColor);
  539. readonlyTextFontColor = getCssStyle(readonlyTextFontColor,"#777777",os.readonlyTextFontColor);
  540. disableBorderColor = getCssStyle(disableBorderColor,"#B4B4B4",os.disableBorderColor);
  541. disableBGColor = getCssStyle(disableBGColor,"#D9D9D0",os.disableBGColor);
  542. disableTextFontColor = getCssStyle(disableTextFontColor,"#777777",os.disableTextFontColor);
  543. mustBorderColor = getCssStyle(mustBorderColor,"#B4B4B4",os.mustBorderColor);
  544. mustBGColor = getCssStyle(mustBGColor,"#FCFBCE",os.mustBGColor);
  545. mustTextFontColor = getCssStyle(mustTextFontColor,"#000000",os.mustTextFontColor);
  546. fontSize1 = getCssStyle(fontSize1,"9pt",os.fontSize1);
  547. fontFamily1 = getCssStyle(fontFamily1,"arial",os.fontFamily1);
  548. element.initcssing = false;
  549. }
  550. </script>