tests_numeric.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("Numeric.Extensions");
  3. qunit.test("€ Currency precision 2", function (assert) {
  4. var done = assert.async(),
  5. $fixture = $("#qunit-fixture");
  6. $fixture.append('<input type="text" id="testmask" />');
  7. var testmask = document.getElementById("testmask");
  8. Inputmask("numeric", {
  9. groupSeparator: ",",
  10. placeholder: "0",
  11. autoGroup: true,
  12. digits: 2,
  13. digitsOptional: false,
  14. prefix: "€ "
  15. }).mask(testmask);
  16. testmask.focus();
  17. $("#testmask").trigger("click");
  18. setTimeout(function () {
  19. $("#testmask").Type("1234");
  20. assert.equal(testmask.value, "€ 1,234.00", "Result " + testmask.value);
  21. done();
  22. }, 0);
  23. });
  24. qunit.test("integer type 124 correct to 1234", function (assert) {
  25. var $fixture = $("#qunit-fixture");
  26. $fixture.append('<input type="text" id="testmask" />');
  27. var testmask = document.getElementById("testmask");
  28. Inputmask("numeric", {
  29. groupSeparator: ",",
  30. autoGroup: true
  31. }).mask(testmask);
  32. testmask.focus();
  33. $("#testmask").Type("124");
  34. $.caret(testmask, 2);
  35. $("#testmask").Type("3");
  36. assert.equal(testmask.value, "1,234", "Result " + testmask.value);
  37. });
  38. qunit.test("numeric type 00000 - Webunity", function (assert) {
  39. var $fixture = $("#qunit-fixture");
  40. $fixture.append('<input type="text" id="testmask" />');
  41. var testmask = document.getElementById("testmask");
  42. Inputmask("numeric", {
  43. groupSeparator: ",",
  44. autoGroup: true,
  45. integerDigits: 9
  46. }).mask(testmask);
  47. testmask.focus();
  48. $("#testmask").Type("00000");
  49. $(testmask).trigger("blur");
  50. assert.equal(testmask.value, "0", "Result " + testmask.value);
  51. });
  52. qunit.test("numeric -placeholder 0 type 00000 - Webunity", function (assert) {
  53. var $fixture = $("#qunit-fixture");
  54. $fixture.append('<input type="text" id="testmask" />');
  55. var testmask = document.getElementById("testmask");
  56. Inputmask("numeric", {
  57. groupSeparator: ",",
  58. autoGroup: true,
  59. placeholder: "0"
  60. }).mask(testmask);
  61. testmask.focus();
  62. $("#testmask").Type("00000");
  63. assert.equal($("#testmask")[0].inputmask._valueGet(), "0", "Result " + testmask.value);
  64. });
  65. qunit.test("numeric placeholder 0 prefix € type 0.123 - Webunity", function (assert) {
  66. var $fixture = $("#qunit-fixture");
  67. $fixture.append('<input type="text" id="testmask" />');
  68. var testmask = document.getElementById("testmask");
  69. Inputmask("numeric", {
  70. groupSeparator: ",",
  71. autoGroup: true,
  72. placeholder: "0",
  73. prefix: "€ "
  74. }).mask(testmask);
  75. testmask.focus();
  76. $("#testmask").Type("0.123");
  77. assert.equal(testmask.value, "€ 0.123", "Result " + testmask.value);
  78. });
  79. qunit.test("numeric placeholder 0 prefix € type 0.123 - backspace - Webunity", function (assert) {
  80. var $fixture = $("#qunit-fixture");
  81. $fixture.append('<input type="text" id="testmask" />');
  82. var testmask = document.getElementById("testmask");
  83. Inputmask("numeric", {
  84. groupSeparator: ",",
  85. autoGroup: true,
  86. placeholder: "0",
  87. prefix: "€ "
  88. }).mask(testmask);
  89. testmask.focus();
  90. $("#testmask").Type("0.123");
  91. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  92. assert.equal(testmask.value, "€ 0.12", "Result " + testmask.value);
  93. });
  94. qunit.test("numeric placeholder 0 prefix € type 0.123 + add 1 in front - Webunity", function (assert) {
  95. var $fixture = $("#qunit-fixture");
  96. $fixture.append('<input type="text" id="testmask" />');
  97. var testmask = document.getElementById("testmask");
  98. Inputmask("numeric", {
  99. groupSeparator: ",",
  100. autoGroup: true,
  101. placeholder: "0",
  102. prefix: "€ "
  103. }).mask(testmask);
  104. testmask.focus();
  105. $("#testmask").Type("0.123");
  106. $.caret(testmask, 2);
  107. $("#testmask").Type("1");
  108. assert.equal(testmask.value, "€ 10.123", "Result " + testmask.value);
  109. });
  110. qunit.test("numeric placeholder 0 autoGroup: false prefix € type 0.123 + add 123 in front - Webunity", function (assert) {
  111. var $fixture = $("#qunit-fixture");
  112. $fixture.append('<input type="text" id="testmask" />');
  113. var testmask = document.getElementById("testmask");
  114. Inputmask("numeric", {
  115. groupSeparator: ",",
  116. autoGroup: false,
  117. placeholder: "0",
  118. prefix: "€ "
  119. }).mask(testmask);
  120. testmask.focus();
  121. $("#testmask").Type("0.123");
  122. $.caret(testmask, 2);
  123. $("#testmask").Type("123");
  124. assert.equal(testmask.value, "€ 1230.123", "Result " + testmask.value);
  125. });
  126. qunit.test("numeric placeholder 0 autoGroup: true prefix € type 0.123 + add 123 in front - Webunity", function (assert) {
  127. var $fixture = $("#qunit-fixture");
  128. $fixture.append('<input type="text" id="testmask" />');
  129. var testmask = document.getElementById("testmask");
  130. Inputmask("numeric", {
  131. groupSeparator: ",",
  132. autoGroup: true,
  133. placeholder: "0",
  134. prefix: "€ "
  135. }).mask(testmask);
  136. testmask.focus();
  137. $("#testmask").Type("0.123");
  138. $.caret(testmask, 2);
  139. $("#testmask").Type("123");
  140. assert.equal(testmask.value, "€ 1,230.123", "Result " + testmask.value);
  141. });
  142. qunit.test("integer alias with integerDigits 9 & autogroup - type 123456789 - gigermocas", function (assert) {
  143. var $fixture = $("#qunit-fixture");
  144. $fixture.append('<input type="text" id="testmask" />');
  145. var testmask = document.getElementById("testmask");
  146. Inputmask("integer", {
  147. groupSeparator: ",",
  148. autoGroup: true,
  149. integerDigits: 9
  150. }).mask(testmask);
  151. testmask.focus();
  152. $("#testmask").Type("123456789");
  153. assert.equal(testmask.value, "123,456,789", "Result " + testmask.value);
  154. });
  155. qunit.test("integer alias with integerDigits 9 & autogroup - type 1234567890123456789 - gigermocas", function (assert) {
  156. var $fixture = $("#qunit-fixture");
  157. $fixture.append('<input type="text" id="testmask" />');
  158. var testmask = document.getElementById("testmask");
  159. Inputmask("integer", {
  160. groupSeparator: ",",
  161. autoGroup: true,
  162. integerDigits: 9
  163. }).mask(testmask);
  164. testmask.focus();
  165. $("#testmask").Type("1234567890123456789");
  166. assert.equal(testmask.value, "123,456,789", "Result " + testmask.value);
  167. });
  168. qunit.test("integer alias with integerDigits 4 & autogroup - type 1234567890123456789 - gigermocas", function (assert) {
  169. var $fixture = $("#qunit-fixture");
  170. $fixture.append('<input type="text" id="testmask" />');
  171. var testmask = document.getElementById("testmask");
  172. Inputmask("integer", {
  173. groupSeparator: ",",
  174. autoGroup: true,
  175. integerDigits: 4
  176. }).mask(testmask);
  177. testmask.focus();
  178. $("#testmask").Type("1234567890123456789");
  179. assert.equal(testmask.value, "1,234", "Result " + testmask.value);
  180. });
  181. qunit.test("decimal alias with integerDigits 9 & autogroup - type 123456789 - gigermocas", function (assert) {
  182. var $fixture = $("#qunit-fixture");
  183. $fixture.append('<input type="text" id="testmask" />');
  184. var testmask = document.getElementById("testmask");
  185. Inputmask("decimal", {
  186. groupSeparator: ",",
  187. autoGroup: true,
  188. integerDigits: 9
  189. }).mask(testmask);
  190. testmask.focus();
  191. $("#testmask").Type("123456789");
  192. assert.equal(testmask.value, "123,456,789", "Result " + testmask.value);
  193. });
  194. qunit.test("decimal alias with integerDigits 4 & autogroup - type 1234 - gigermocas", function (assert) {
  195. var $fixture = $("#qunit-fixture");
  196. $fixture.append('<input type="text" id="testmask" />');
  197. var testmask = document.getElementById("testmask");
  198. Inputmask("decimal", {
  199. groupSeparator: ",",
  200. autoGroup: true,
  201. integerDigits: 4
  202. }).mask(testmask);
  203. testmask.focus();
  204. $("#testmask").Type("1234");
  205. assert.equal(testmask.value, "1,234", "Result " + testmask.value);
  206. });
  207. qunit.test("numeric alias with allowMinus:false type=text - vijjj", function (assert) {
  208. var $fixture = $("#qunit-fixture");
  209. $fixture.append('<input type="text" id="testmask" />');
  210. var testmask = document.getElementById("testmask");
  211. Inputmask("numeric", {
  212. radixPoint: ".",
  213. integerDigits: 6,
  214. allowMinus: false
  215. }).mask(testmask);
  216. testmask.focus();
  217. $("#testmask").Type("123456");
  218. $.caret(testmask, 0);
  219. $("#testmask").SendKey("-");
  220. assert.equal(testmask.value, "123456", "Result " + testmask.value);
  221. });
  222. qunit.test("numeric alias with allowMinus:false type=number - mask not applied - MartinVerges", function (assert) {
  223. var $fixture = $("#qunit-fixture");
  224. $fixture.append('<input type="number" id="testmask" />');
  225. var testmask = document.getElementById("testmask");
  226. Inputmask("numeric", {
  227. radixPoint: ".",
  228. integerDigits: 6,
  229. allowMinus: false
  230. }).mask(testmask);
  231. testmask.focus();
  232. $("#testmask").Type("123456");
  233. $("#testmask").SendKey("-");
  234. //IE7 does not know type=number and treats as type=text
  235. //noinspection JSUnresolvedFunction
  236. assert.ok(testmask.value === "" || testmask.value === "123456", "Result " + testmask.value);
  237. });
  238. qunit.test("inputmask(\"numeric\", { prefix: \"€ \" }\") - input 12345.12", function (assert) {
  239. var $fixture = $("#qunit-fixture");
  240. $fixture.append('<input type="text" id="testmask" />');
  241. var testmask = document.getElementById("testmask");
  242. Inputmask("numeric", {
  243. prefix: "€ "
  244. }).mask(testmask);
  245. testmask.focus();
  246. $("#testmask").Type("12345.12");
  247. assert.equal(testmask.value, "€ 12345.12", "Result " + testmask.value);
  248. });
  249. qunit.test("inputmask(\"decimal\", { autoGroup: true, groupSeparator: \",\" }\") - input 12345.123", function (assert) {
  250. var $fixture = $("#qunit-fixture");
  251. $fixture.append('<input type="text" id="testmask" />');
  252. var testmask = document.getElementById("testmask");
  253. Inputmask("decimal", {
  254. autoGroup: true,
  255. groupSeparator: ","
  256. }).mask(testmask);
  257. testmask.focus();
  258. $("#testmask").SendKey("1");
  259. $("#testmask").SendKey("2");
  260. $("#testmask").SendKey("3");
  261. $("#testmask").SendKey("4");
  262. $("#testmask").SendKey("5");
  263. $("#testmask").SendKey(".");
  264. $("#testmask").SendKey("1");
  265. $("#testmask").SendKey("2");
  266. $("#testmask").SendKey("3");
  267. assert.equal(testmask.value, "12,345.123", "Result " + testmask.value);
  268. });
  269. qunit.test("inputmask(\"decimal\", { autoGroup: true, groupSeparator: \",\", decimalProtect: true }\") - input 12345.123 + remove .123", function (assert) {
  270. var done = assert.async(),
  271. $fixture = $("#qunit-fixture");
  272. $fixture.append('<input type="text" id="testmask" />');
  273. var testmask = document.getElementById("testmask");
  274. Inputmask("decimal", {
  275. autoGroup: true,
  276. groupSeparator: ",",
  277. decimalProtect: true
  278. }).mask(testmask);
  279. testmask.focus();
  280. $("#testmask").Type("12345.123");
  281. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  282. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  283. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  284. $(testmask).trigger("blur");
  285. setTimeout(function () {
  286. assert.equal(testmask.value, "12,345", "Result " + testmask.value);
  287. done();
  288. }, 0);
  289. });
  290. qunit.test("inputmask(\"decimal\", { autoGroup: true, groupSeparator: \",\" }\") - input 12345.123 + replace .123 => .789", function (assert) {
  291. var $fixture = $("#qunit-fixture");
  292. $fixture.append('<input type="text" id="testmask" />');
  293. var testmask = document.getElementById("testmask");
  294. Inputmask("decimal", {
  295. autoGroup: true,
  296. groupSeparator: ","
  297. }).mask(testmask);
  298. testmask.focus();
  299. $("#testmask").Type("12345.123");
  300. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  301. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  302. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  303. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  304. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  305. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  306. $("#testmask").Type(".789");
  307. assert.equal(testmask.value, "12,345.789", "Result " + testmask.value);
  308. });
  309. qunit.test("inputmask(\"decimal\", { autoGroup: true, groupSeparator: \",\" }\") - input 12345.123 + select replace .123 => .789", function (assert) {
  310. var $fixture = $("#qunit-fixture");
  311. $fixture.append('<input type="text" id="testmask" />');
  312. var testmask = document.getElementById("testmask");
  313. Inputmask("decimal", {
  314. autoGroup: true,
  315. groupSeparator: ","
  316. }).mask(testmask);
  317. testmask.focus();
  318. $("#testmask").Type("12345.123");
  319. //$("#testmask").trigger("click");
  320. $.caret(testmask, 6, 10);
  321. $("#testmask").Type(".789");
  322. assert.equal(testmask.value, "12,345.789", "Result " + testmask.value);
  323. });
  324. qunit.test("inputmask(\"decimal\", { autoGroup: false, groupSeparator: \",\", decimalProtect: true }\") - input 12345.123 + remove .123", function (assert) {
  325. var $fixture = $("#qunit-fixture");
  326. $fixture.append('<input type="text" id="testmask" />');
  327. var testmask = document.getElementById("testmask");
  328. Inputmask("decimal", {
  329. autoGroup: false,
  330. groupSeparator: ",",
  331. decimalProtect: true
  332. }).mask(testmask);
  333. testmask.focus();
  334. $("#testmask").Type("12345.123");
  335. //$("#testmask").trigger("click");
  336. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  337. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  338. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  339. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  340. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  341. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  342. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  343. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  344. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  345. });
  346. qunit.test("inputmask(\"decimal\", { autoGroup: false, groupSeparator: \",\", decimalProtect: false }\") - input 12345.123 + remove .123", function (assert) {
  347. var $fixture = $("#qunit-fixture");
  348. $fixture.append('<input type="text" id="testmask" />');
  349. var testmask = document.getElementById("testmask");
  350. Inputmask("decimal", {
  351. autoGroup: false,
  352. groupSeparator: ",",
  353. decimalProtect: false
  354. }).mask(testmask);
  355. testmask.focus();
  356. $("#testmask").Type("12345.123");
  357. //$("#testmask").trigger("click");
  358. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  359. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  360. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  361. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  362. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  363. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  364. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  365. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  366. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  367. });
  368. qunit.test("inputmask(\"decimal\", { autoGroup: false, groupSeparator: \",\", decimalProtect: true }\") - input 12345.123 + replace .123 => .789", function (assert) {
  369. var $fixture = $("#qunit-fixture");
  370. $fixture.append('<input type="text" id="testmask" />');
  371. var testmask = document.getElementById("testmask");
  372. Inputmask("decimal", {
  373. autoGroup: false,
  374. groupSeparator: ",",
  375. decimalProtect: true
  376. }).mask(testmask);
  377. testmask.focus();
  378. $("#testmask").Type("12345.123");
  379. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  380. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  381. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  382. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  383. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  384. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  385. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  386. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  387. $("#testmask").Type(".789");
  388. assert.equal(testmask.value, "12345.789", "Result " + testmask.value);
  389. });
  390. qunit.test("inputmask(\"decimal\") - maxlength 10", function (assert) {
  391. var $fixture = $("#qunit-fixture");
  392. $fixture.append('<input type="text" id="testmask" maxlength="10" />');
  393. var testmask = document.getElementById("testmask");
  394. Inputmask("decimal").mask(testmask);
  395. testmask.focus();
  396. $("#testmask").Type("123456789012345");
  397. assert.equal(testmask.value, "1234567890", "Result " + testmask.value);
  398. });
  399. qunit.test("inputmask(\"decimal, { repeat: 15 }\") - maxlength 10", function (assert) {
  400. var $fixture = $("#qunit-fixture");
  401. $fixture.append('<input type="text" id="testmask" maxlength="10" />');
  402. var testmask = document.getElementById("testmask");
  403. Inputmask("decimal", {
  404. repeat: 15
  405. }).mask(testmask);
  406. testmask.focus();
  407. $("#testmask").Type("123456789012345");
  408. assert.equal(testmask.value, "1234567890", "Result " + testmask.value);
  409. });
  410. qunit.test("inputmask(\"decimal, { repeat: 5, decimalProtect: true }\") - maxlength 10", function (assert) {
  411. var $fixture = $("#qunit-fixture");
  412. $fixture.append('<input type="text" id="testmask" maxlength="10" />');
  413. var testmask = document.getElementById("testmask");
  414. Inputmask("decimal", {
  415. repeat: 5,
  416. decimalProtect: true
  417. }).mask(testmask);
  418. testmask.focus();
  419. $("#testmask").Type("123456789012345");
  420. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  421. });
  422. qunit.test("inputmask(\"decimal, { repeat: 5, decimalProtect: false }\") - maxlength 10", function (assert) {
  423. var $fixture = $("#qunit-fixture");
  424. $fixture.append('<input type="text" id="testmask" maxlength="10" />');
  425. var testmask = document.getElementById("testmask");
  426. Inputmask("decimal", {
  427. repeat: 5,
  428. decimalProtect: false
  429. }).mask(testmask);
  430. testmask.focus();
  431. $("#testmask").Type("123456789012345");
  432. assert.equal(testmask.value, "12345.6789", "Result " + testmask.value);
  433. });
  434. qunit.test("inputmask(\"decimal\")", function (assert) {
  435. var $fixture = $("#qunit-fixture");
  436. $fixture.append('<input type="text" id="testmask" />');
  437. var testmask = document.getElementById("testmask");
  438. Inputmask("decimal").mask(testmask);
  439. testmask.focus();
  440. $("#testmask").Type("1234567890");
  441. $.caret(testmask, 0, 10);
  442. $("#testmask").Type("12345");
  443. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  444. });
  445. qunit.test("inputmask(\"decimal\") - value=\"1234567890\"", function (assert) {
  446. var $fixture = $("#qunit-fixture");
  447. $fixture.append('<input type="text" id="testmask" value="1234567890" />');
  448. var testmask = document.getElementById("testmask");
  449. Inputmask("decimal").mask(testmask);
  450. testmask.focus();
  451. $.caret(testmask, 0, 10);
  452. $("#testmask").Type("12345");
  453. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  454. });
  455. qunit.test("inputmask(\"decimal\")", function (assert) {
  456. var $fixture = $("#qunit-fixture");
  457. $fixture.append('<input type="text" id="testmask" />');
  458. var testmask = document.getElementById("testmask");
  459. Inputmask("decimal").mask(testmask);
  460. testmask.focus();
  461. $("#testmask").Type("1234567890");
  462. $.caret(testmask, 3, 5);
  463. $("#testmask").SendKey("0");
  464. assert.equal(testmask.value, "123067890", "Result " + testmask.value);
  465. });
  466. qunit.test("inputmask(\"decimal\") - value=\"1234567890\"", function (assert) {
  467. var $fixture = $("#qunit-fixture");
  468. $fixture.append('<input type="text" id="testmask" value="1234567890" />');
  469. var testmask = document.getElementById("testmask");
  470. Inputmask("decimal").mask(testmask);
  471. testmask.focus();
  472. $.caret(testmask, 3, 5);
  473. $("#testmask").SendKey("0");
  474. assert.equal(testmask.value, "123067890", "Result " + testmask.value);
  475. });
  476. qunit.test("inputmask(\"decimal\") - value=\"123.45\" Replace last integer", function (assert) {
  477. var $fixture = $("#qunit-fixture");
  478. $fixture.append('<input type="text" id="testmask" />');
  479. var testmask = document.getElementById("testmask");
  480. Inputmask("decimal", {
  481. digits: 2
  482. }).mask(testmask);
  483. testmask.focus();
  484. $("#testmask").Type("123.45");
  485. $.caret(testmask, 2, 3);
  486. $("#testmask").SendKey("7");
  487. assert.equal(testmask.value, "127.45", "Result " + testmask.value);
  488. });
  489. qunit.test("inputmask(\"decimal\", { digits: 2 }) - value=\"123\" - RomeroMsk", function (assert) {
  490. var $fixture = $("#qunit-fixture");
  491. $fixture.append('<input type="text" id="testmask" />');
  492. var testmask = document.getElementById("testmask");
  493. Inputmask("decimal", {
  494. digits: 2
  495. }).mask(testmask);
  496. testmask.focus();
  497. $("#testmask").Type("123");
  498. $.caret(testmask, 0, 3);
  499. $("#testmask").Type(",,..");
  500. $("#testmask").Type("45");
  501. assert.equal(testmask.value, "0.45", "Result " + testmask.value);
  502. });
  503. qunit.test("inputmask - Multiple inputs masked, Integer mask doesn't allow typing - #402 - albatrocity", function (assert) {
  504. var $fixture = $("#qunit-fixture");
  505. $fixture.append('<input type="text" id="testmask" />');
  506. var testmask = document.getElementById("testmask");
  507. $fixture.append('<input type="text" id="testmask2" />');
  508. var testmask2 = document.getElementById("testmask2");
  509. Inputmask("integer", {
  510. autoGroup: true,
  511. groupSeparator: ",",
  512. groupSize: 3
  513. }).mask(testmask);
  514. Inputmask("(999)-999-9999").mask(testmask2);
  515. testmask.focus();
  516. $("#testmask").Type("12345");
  517. assert.equal(testmask.value, "12,345", "Result " + testmask.value);
  518. $("#testmask2").remove();
  519. });
  520. qunit.test("decimal alias with groupseparator delete - YoussefTaghlabi", function (assert) {
  521. var $fixture = $("#qunit-fixture");
  522. $fixture.append('<input type="text" id="testmask" />');
  523. var testmask = document.getElementById("testmask");
  524. Inputmask("decimal", {
  525. radixPoint: ".",
  526. groupSeparator: ",",
  527. groupSize: 3,
  528. digits: 2,
  529. autoGroup: true,
  530. allowPlus: false,
  531. allowMinus: true
  532. }).mask(testmask);
  533. testmask.focus();
  534. $("#testmask").Type("1234567");
  535. $.caret(testmask, 0);
  536. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  537. assert.equal(testmask.value, "234,567", "Result " + testmask.value);
  538. });
  539. qunit.test("decimal alias with groupseparator backspace - YoussefTaghlabi", function (assert) {
  540. var $fixture = $("#qunit-fixture");
  541. $fixture.append('<input type="text" id="testmask" />');
  542. var testmask = document.getElementById("testmask");
  543. Inputmask("decimal", {
  544. radixPoint: ".",
  545. groupSeparator: ",",
  546. groupSize: 3,
  547. digits: 2,
  548. autoGroup: true,
  549. allowPlus: false,
  550. allowMinus: true
  551. }).mask(testmask);
  552. testmask.focus();
  553. $("#testmask").Type("1234567");
  554. $.caret(testmask, 1);
  555. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  556. assert.equal(testmask.value, "234,567", "Result " + testmask.value);
  557. });
  558. qunit.test("decimal alias with plus or minus & autogroup - type -123456 - YoussefTaghlabi", function (assert) {
  559. var $fixture = $("#qunit-fixture");
  560. $fixture.append('<input type="text" id="testmask" />');
  561. var testmask = document.getElementById("testmask");
  562. Inputmask("decimal", {
  563. radixPoint: ".",
  564. groupSeparator: ",",
  565. groupSize: 3,
  566. digits: 2,
  567. autoGroup: true,
  568. allowPlus: true,
  569. allowMinus: true
  570. }).mask(testmask);
  571. testmask.focus();
  572. $("#testmask").Type("-123456");
  573. assert.equal(testmask.value, "-123,456", "Result " + testmask.value);
  574. });
  575. qunit.test("decimal alias with plus or minus & autogroup - type 123465 - - YoussefTaghlabi", function (assert) {
  576. var $fixture = $("#qunit-fixture");
  577. $fixture.append('<input type="text" id="testmask" />');
  578. var testmask = document.getElementById("testmask");
  579. Inputmask("decimal", {
  580. radixPoint: ".",
  581. groupSeparator: ",",
  582. groupSize: 3,
  583. digits: 2,
  584. autoGroup: true,
  585. allowPlus: true,
  586. allowMinus: true
  587. }).mask(testmask);
  588. testmask.focus();
  589. $("#testmask").Type("123456");
  590. $.caret(testmask, 0);
  591. $("#testmask").SendKey("-");
  592. assert.equal(testmask.value, "-123,456", "Result " + testmask.value);
  593. });
  594. qunit.test("decimal alias with plus or minus & autogroup", function (assert) {
  595. var $fixture = $("#qunit-fixture");
  596. $fixture.append('<input type="text" id="testmask" />');
  597. var testmask = document.getElementById("testmask");
  598. Inputmask("decimal", {
  599. radixPoint: ".",
  600. groupSeparator: ",",
  601. groupSize: 3,
  602. digits: 2,
  603. autoGroup: true,
  604. allowPlus: true,
  605. allowMinus: true
  606. }).mask(testmask);
  607. testmask.focus();
  608. $("#testmask").Type("1234.56");
  609. assert.equal(testmask.value, "1,234.56", "Result " + testmask.value);
  610. });
  611. qunit.test("decimal alias set value with val() - kochelmonster", function (assert) {
  612. var $fixture = $("#qunit-fixture");
  613. $fixture.append('<input type="text" id="testmask" />');
  614. var testmask = document.getElementById("testmask");
  615. Inputmask("decimal", {
  616. radixPoint: ",",
  617. groupSeparator: ".",
  618. digits: 2,
  619. autoGroup: true,
  620. suffix: ' €'
  621. }).mask(testmask);
  622. $("#testmask").val("39.399.392,22 €");
  623. assert.equal(testmask.value, "39.399.392,22 €", "Result " + testmask.value);
  624. });
  625. qunit.test("inputmask(\"decimal\") - value=\"123.1\" blur digitsoptional", function (assert) {
  626. var done = assert.async(),
  627. $fixture = $("#qunit-fixture");
  628. $fixture.append('<input type="text" id="testmask" />');
  629. var testmask = document.getElementById("testmask");
  630. Inputmask("decimal", {
  631. digits: 3
  632. }).mask(testmask);
  633. testmask.focus();
  634. $("#testmask").Type("123.1");
  635. $(testmask).trigger("blur");
  636. setTimeout(function () {
  637. assert.equal(testmask.value, "123.1", "Result " + testmask.value);
  638. done();
  639. }, 0);
  640. });
  641. qunit.test("inputmask(\"decimal\") - value=\"123.1\" blur", function (assert) {
  642. var done = assert.async(),
  643. $fixture = $("#qunit-fixture");
  644. $fixture.append('<input type="text" id="testmask" />');
  645. var testmask = document.getElementById("testmask");
  646. Inputmask("decimal", {
  647. digits: 3,
  648. digitsOptional: false
  649. }).mask(testmask);
  650. testmask.focus();
  651. $("#testmask").Type("123.1");
  652. $(testmask).trigger("blur");
  653. setTimeout(function () {
  654. assert.equal(testmask.value, "123.100", "Result " + testmask.value);
  655. done();
  656. }, 0);
  657. });
  658. qunit.test("currency alias - 200000 => replace 2 to 3", function (assert) {
  659. var done = assert.async(),
  660. $fixture = $("#qunit-fixture");
  661. $fixture.append('<input type="text" id="testmask" />');
  662. var testmask = document.getElementById("testmask");
  663. Inputmask("currency").mask(testmask);
  664. testmask.focus();
  665. $("#testmask").trigger("click");
  666. setTimeout(function () {
  667. $("#testmask").Type("200000");
  668. $.caret(testmask, 2, 3);
  669. $("#testmask").Type("3");
  670. assert.equal(testmask.value, "$ 300,000.00", "Result " + testmask.value);
  671. done();
  672. }, 5);
  673. });
  674. qunit.test("inputmask(\"integer\") - -0 - laxmikantG", function (assert) {
  675. var done = assert.async(),
  676. $fixture = $("#qunit-fixture");
  677. $fixture.append('<input type="text" id="testmask" />');
  678. var testmask = document.getElementById("testmask");
  679. Inputmask("integer", {
  680. placeholder: "0"
  681. }).mask(testmask);
  682. testmask.focus();
  683. $("#testmask").Type("-0");
  684. $(testmask).trigger("blur");
  685. setTimeout(function () {
  686. assert.equal(testmask.value, "0", "Result " + testmask.value);
  687. done();
  688. }, 0);
  689. });
  690. qunit.test("inputmask(\"integer\") - 123- - laxmikantG", function (assert) {
  691. var $fixture = $("#qunit-fixture");
  692. $fixture.append('<input type="text" id="testmask" />');
  693. var testmask = document.getElementById("testmask");
  694. Inputmask("integer", {
  695. placeholder: "0"
  696. }).mask(testmask);
  697. testmask.focus();
  698. $("#testmask").Type("123-");
  699. assert.equal(testmask.value, "-123", "Result " + testmask.value);
  700. });
  701. qunit.test("inputmask(\"decimal\") - val(\"-5000,77\"); - ManRueda", function (assert) {
  702. var $fixture = $("#qunit-fixture");
  703. $fixture.append('<input type="text" id="testmask" />');
  704. var testmask = document.getElementById("testmask");
  705. Inputmask('decimal', {
  706. integerDigits: 10,
  707. groupSeparator: '.',
  708. autoGroup: true,
  709. digits: 2,
  710. radixPoint: ',',
  711. groupSize: 3
  712. }).mask(testmask);
  713. $("#testmask").val("-5000,77");
  714. assert.equal(testmask.value, "-5.000,77", "Result " + testmask.value);
  715. });
  716. qunit.test("inputmask(\"decimal\") - -0 - ManRueda", function (assert) {
  717. var done = assert.async(),
  718. $fixture = $("#qunit-fixture");
  719. $fixture.append('<input type="text" id="testmask" />');
  720. var testmask = document.getElementById("testmask");
  721. Inputmask('decimal', {
  722. integerDigits: 10,
  723. groupSeparator: '.',
  724. autoGroup: true,
  725. digits: 2,
  726. radixPoint: ',',
  727. groupSize: 3
  728. }).mask(testmask);
  729. $("#testmask").val("-0");
  730. $(testmask).trigger("blur");
  731. setTimeout(function () {
  732. assert.equal(testmask.value, "0", "Result " + testmask.value);
  733. done();
  734. }, 0);
  735. });
  736. qunit.test("inputmask(\"integer\") - -5.000,77 - DrSammyD", function (assert) {
  737. var $fixture = $("#qunit-fixture");
  738. $fixture.append('<input type="text" id="testmask" />');
  739. var testmask = document.getElementById("testmask");
  740. Inputmask('integer', {
  741. placeholder: "0"
  742. }).mask(testmask);
  743. $("#testmask").val("-5.000,77");
  744. $(testmask).trigger("blur");
  745. assert.equal(testmask.value, "-5000", "Result " + testmask.value);
  746. });
  747. qunit.test("inputmask(\"decimal\ placeholder :\"\" digitsoptional: false) - 123 - loostro", function (assert) {
  748. var done = assert.async(),
  749. $fixture = $("#qunit-fixture");
  750. $fixture.append('<input type="text" id="testmask" value="0,00" />');
  751. var testmask = document.getElementById("testmask");
  752. Inputmask("decimal", {
  753. radixPoint: ",",
  754. digits: 2,
  755. digitsOptional: false,
  756. autoGroup: true,
  757. groupSeparator: " ",
  758. groupSize: 3,
  759. allowPlus: false,
  760. allowMinus: false
  761. }).mask(testmask);
  762. testmask.focus();
  763. $("#testmask").trigger("click");
  764. $.caret(testmask, 0);
  765. setTimeout(function () {
  766. $("#testmask").Type("123");
  767. assert.equal(testmask.value, "123,00", "Result " + testmask.value);
  768. done();
  769. }, 5);
  770. });
  771. qunit.test("inputmask(\"decimal\ placeholder :\"0\" digitsoptional: false) - .12 - YodaJM", function (assert) {
  772. var done = assert.async(),
  773. $fixture = $("#qunit-fixture");
  774. $fixture.append('<input type="text" id="testmask" />');
  775. var testmask = document.getElementById("testmask");
  776. Inputmask('decimal', {
  777. digits: 2,
  778. placeholder: "0",
  779. digitsOptional: false
  780. }).mask(testmask);
  781. testmask.focus();
  782. $.caret(testmask, 0, 4);
  783. setTimeout(function () {
  784. $("#testmask").Type(".12");
  785. assert.equal(testmask.value, "0.12", "Result " + testmask.value);
  786. done();
  787. }, 0);
  788. });
  789. qunit.test("inputmask(\"decimal\") - '8100000.00' - ManRueda", function (assert) {
  790. var $fixture = $("#qunit-fixture");
  791. $fixture.append('<input type="text" id="testmask" />');
  792. var testmask = document.getElementById("testmask");
  793. Inputmask('decimal', {
  794. integerDigits: 6,
  795. groupSeparator: '.',
  796. autoGroup: true,
  797. digits: 2,
  798. radixPoint: ',',
  799. groupSize: 3
  800. }).mask(testmask);
  801. $("#testmask").val("8100000.00");
  802. assert.equal(testmask.value, "810.000,00", "Result " + testmask.value);
  803. });
  804. qunit.test("inputmask(\"decimal\") - '12345678.12' - ManRueda", function (assert) {
  805. var $fixture = $("#qunit-fixture");
  806. $fixture.append('<input type="text" id="testmask" />');
  807. var testmask = document.getElementById("testmask");
  808. Inputmask('decimal', {
  809. integerDigits: 6,
  810. groupSeparator: '.',
  811. autoGroup: true,
  812. digits: 2,
  813. radixPoint: ',',
  814. groupSize: 3
  815. }).mask(testmask);
  816. $("#testmask").val("12345678.12");
  817. assert.equal(testmask.value, "123.456,12", "Result " + testmask.value);
  818. });
  819. qunit.test("inputmask(\"decimal\") - '8100000,00' - ManRueda", function (assert) {
  820. var $fixture = $("#qunit-fixture");
  821. $fixture.append('<input type="text" id="testmask" />');
  822. var testmask = document.getElementById("testmask");
  823. Inputmask('decimal', {
  824. integerDigits: 6,
  825. groupSeparator: '.',
  826. autoGroup: true,
  827. digits: 2,
  828. radixPoint: ',',
  829. groupSize: 3
  830. }).mask(testmask);
  831. $("#testmask").val("8100000,00");
  832. assert.equal(testmask.value, "810.000,00", "Result " + testmask.value);
  833. });
  834. qunit.test("inputmask(\"decimal\") - 8100000.00 - ManRueda", function (assert) {
  835. var $fixture = $("#qunit-fixture");
  836. $fixture.append('<input type="text" id="testmask" />');
  837. var testmask = document.getElementById("testmask");
  838. Inputmask('decimal', {
  839. integerDigits: 6,
  840. groupSeparator: '.',
  841. autoGroup: true,
  842. digits: 2,
  843. radixPoint: ',',
  844. groupSize: 3
  845. }).mask(testmask);
  846. $("#testmask").val(8100000.00);
  847. assert.equal(testmask.value, "810.000", "Result " + testmask.value);
  848. });
  849. qunit.test("inputmask(\"decimal\") - 8100000.00 digitsoptional false - ManRueda", function (assert) {
  850. var $fixture = $("#qunit-fixture");
  851. $fixture.append('<input type="text" id="testmask" />');
  852. var testmask = document.getElementById("testmask");
  853. Inputmask('decimal', {
  854. integerDigits: 6,
  855. groupSeparator: '.',
  856. autoGroup: true,
  857. digits: 2,
  858. digitsOptional: false,
  859. radixPoint: ',',
  860. groupSize: 3
  861. }).mask(testmask);
  862. $("#testmask").val(8100000.00);
  863. $(testmask).trigger("blur");
  864. assert.equal(testmask.value, "810.000,00", "Result " + testmask.value);
  865. });
  866. qunit.test("inputmask(\"decimal\") - 810000.00 - ManRueda", function (assert) {
  867. var $fixture = $("#qunit-fixture");
  868. $fixture.append('<input type="text" id="testmask" />');
  869. var testmask = document.getElementById("testmask");
  870. Inputmask("decimal", {
  871. integerDigits: 6,
  872. groupSeparator: ".",
  873. autoGroup: true,
  874. digits: 2,
  875. radixPoint: ",",
  876. groupSize: 3
  877. }).mask(testmask);
  878. $("#testmask").val("810000.00");
  879. assert.equal(testmask.value, "810.000,00", "Result " + testmask.value);
  880. });
  881. qunit.test("inputmask(\"decimal\") - 123456 78 - babupca", function (assert) {
  882. var done = assert.async(),
  883. $fixture = $("#qunit-fixture");
  884. $fixture.append('<input type="text" id="testmask" />');
  885. var testmask = document.getElementById("testmask");
  886. Inputmask({
  887. alias: "decimal",
  888. integerDigits: 6,
  889. digits: 3,
  890. allowMinus: false,
  891. digitsOptional: false,
  892. placeholder: "0"
  893. }).mask(testmask);
  894. testmask.focus();
  895. $("#testmask").trigger("click");
  896. setTimeout(function () {
  897. $("#testmask").Type("123456");
  898. $.caret(testmask, 8);
  899. $("#testmask").Type("78");
  900. $.caret(testmask, 5);
  901. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  902. assert.equal(testmask.value, "12346.078", "Result " + testmask.value);
  903. done();
  904. }, 0);
  905. });
  906. qunit.test("currency alias - 1234 => del 1", function (assert) {
  907. var done = assert.async(),
  908. $fixture = $("#qunit-fixture");
  909. $fixture.append('<input type="text" id="testmask" />');
  910. var testmask = document.getElementById("testmask");
  911. Inputmask("currency").mask(testmask);
  912. testmask.focus();
  913. $("#testmask").trigger("click");
  914. setTimeout(function () {
  915. $("#testmask").Type("1234");
  916. $.caret(testmask, 3);
  917. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  918. assert.equal(testmask.value, "$ 234.00", "Result " + testmask.value);
  919. done();
  920. }, 5);
  921. });
  922. qunit.test("currency alias - 0.02 => type 1 in integer part", function (assert) {
  923. var done = assert.async(),
  924. $fixture = $("#qunit-fixture");
  925. $fixture.append('<input type="text" id="testmask" />');
  926. var testmask = document.getElementById("testmask");
  927. Inputmask("currency").mask(testmask);
  928. testmask.focus();
  929. $("#testmask").trigger("click");
  930. setTimeout(function () {
  931. $("#testmask").Type("0.02");
  932. $.caret(testmask, 3);
  933. $("#testmask").SendKey("1");
  934. assert.equal(testmask.value, "$ 1.02", "Result " + testmask.value);
  935. done();
  936. }, 5);
  937. });
  938. qunit.test("currency alias - 0.02 => position before 0 type 1 in integer part", function (assert) {
  939. var done = assert.async(),
  940. $fixture = $("#qunit-fixture");
  941. $fixture.append('<input type="text" id="testmask" />');
  942. var testmask = document.getElementById("testmask");
  943. Inputmask("currency").mask(testmask);
  944. testmask.focus();
  945. $("#testmask").trigger("click");
  946. setTimeout(function () {
  947. $("#testmask").Type("0.02");
  948. $.caret(testmask, 2);
  949. $("#testmask").SendKey("1");
  950. assert.equal(testmask.value, "$ 10.02", "Result " + testmask.value);
  951. done();
  952. }, 5);
  953. });
  954. qunit.test("currency alias - 1.23 => del 1 in integer part", function (assert) {
  955. var done = assert.async(),
  956. $fixture = $("#qunit-fixture");
  957. $fixture.append('<input type="text" id="testmask" />');
  958. var testmask = document.getElementById("testmask");
  959. Inputmask("currency").mask(testmask);
  960. testmask.focus();
  961. $("#testmask").trigger("click");
  962. setTimeout(function () {
  963. $("#testmask").Type("1.23");
  964. $.caret(testmask, 3);
  965. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  966. assert.equal(testmask.value, "$ 0.23", "Result " + testmask.value);
  967. done();
  968. }, 5);
  969. });
  970. qunit.test("currency alias - 1234.56 => delete all", function (assert) {
  971. var done = assert.async(),
  972. $fixture = $("#qunit-fixture");
  973. $fixture.append('<input type="text" id="testmask" />');
  974. var testmask = document.getElementById("testmask");
  975. Inputmask("currency").mask(testmask);
  976. testmask.focus();
  977. $("#testmask").trigger("click");
  978. setTimeout(function () {
  979. $("#testmask").Type("1234.56");
  980. $.caret(testmask, 0, 10);
  981. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  982. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 0.00", "Result " + $("#testmask")[0].inputmask._valueGet());
  983. done();
  984. }, 5);
  985. });
  986. qunit.test("numeric prefix='$' - paste 1234.56 - baileyjames9 & TheAndyBob", function (assert) {
  987. var done = assert.async(),
  988. $fixture = $("#qunit-fixture");
  989. $fixture.append('<input type="text" id="testmask" />');
  990. var testmask = document.getElementById("testmask");
  991. Inputmask("numeric", {
  992. radixPoint: ".",
  993. groupSeparator: ",",
  994. digits: 2,
  995. autoGroup: true,
  996. prefix: '$' //No Space, this will truncate the first character
  997. }).mask(testmask);
  998. testmask.focus();
  999. $("#testmask").trigger("click");
  1000. setTimeout(function () {
  1001. $("#testmask").paste("1234.56");
  1002. assert.equal(testmask.value, "$1,234.56", "Result " + testmask.value);
  1003. done();
  1004. }, 5);
  1005. });
  1006. qunit.test("currency alias - 1234.56 => select integer press 1 - babupca", function (assert) {
  1007. var done = assert.async(),
  1008. $fixture = $("#qunit-fixture");
  1009. $fixture.append('<input type="text" id="testmask" />');
  1010. var testmask = document.getElementById("testmask");
  1011. Inputmask("currency").mask(testmask);
  1012. testmask.focus();
  1013. $("#testmask").trigger("click");
  1014. setTimeout(function () {
  1015. $("#testmask").Type("1234.56");
  1016. $.caret(testmask, 0, 7);
  1017. $("#testmask").SendKey("1");
  1018. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 1.56", "Result " + $("#testmask")[0].inputmask._valueGet());
  1019. done();
  1020. }, 5);
  1021. });
  1022. qunit.test("currency alias - 123.56 => select integer press 1 - babupca", function (assert) {
  1023. var done = assert.async(),
  1024. $fixture = $("#qunit-fixture");
  1025. $fixture.append('<input type="text" id="testmask" />');
  1026. var testmask = document.getElementById("testmask");
  1027. Inputmask("currency").mask(testmask);
  1028. testmask.focus();
  1029. $("#testmask").trigger("click");
  1030. setTimeout(function () {
  1031. $("#testmask").Type("123.56");
  1032. $.caret(testmask, 0, 5);
  1033. $("#testmask").SendKey("1");
  1034. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 1.56", "Result " + $("#testmask")[0].inputmask._valueGet());
  1035. done();
  1036. }, 5);
  1037. });
  1038. qunit.test("currency alias - 123.56 => select integer press 1 - babupca", function (assert) {
  1039. var done = assert.async(),
  1040. $fixture = $("#qunit-fixture");
  1041. $fixture.append('<input type="text" id="testmask" />');
  1042. var testmask = document.getElementById("testmask");
  1043. Inputmask("currency", {
  1044. prefix: "$"
  1045. }).mask(testmask);
  1046. testmask.focus();
  1047. $("#testmask").trigger("click");
  1048. setTimeout(function () {
  1049. $("#testmask").Type("123.56");
  1050. $.caret(testmask, 0, 4);
  1051. $("#testmask").SendKey("1");
  1052. assert.equal($("#testmask")[0].inputmask._valueGet(), "$1.56", "Result " + $("#testmask")[0].inputmask._valueGet());
  1053. done();
  1054. }, 5);
  1055. });
  1056. qunit.test("currency alias - min 1000", function (assert) {
  1057. var done = assert.async(),
  1058. $fixture = $("#qunit-fixture");
  1059. $fixture.append('<input type="text" id="testmask" />');
  1060. var testmask = document.getElementById("testmask");
  1061. Inputmask("currency", {
  1062. min: 1000
  1063. }).mask(testmask);
  1064. testmask.focus();
  1065. $(testmask).trigger("blur");
  1066. setTimeout(function () {
  1067. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 1,000.00", "Result " + $("#testmask")[0].inputmask._valueGet());
  1068. done();
  1069. }, 5);
  1070. });
  1071. qunit.test("currency alias - max 1000 - type 1234", function (assert) {
  1072. var done = assert.async(),
  1073. $fixture = $("#qunit-fixture");
  1074. $fixture.append('<input type="text" id="testmask" />');
  1075. var testmask = document.getElementById("testmask");
  1076. Inputmask("currency", {
  1077. max: 1000
  1078. }).mask(testmask);
  1079. testmask.focus();
  1080. $("#testmask").trigger("click");
  1081. setTimeout(function () {
  1082. $("#testmask").Type("1234");
  1083. $("#testmask").trigger("blur");
  1084. setTimeout(function () {
  1085. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 1,000.00", "Result " + $("#testmask")[0].inputmask._valueGet());
  1086. done();
  1087. }, 0);
  1088. }, 5);
  1089. });
  1090. qunit.test("currency alias - type 1010 delete first 1 - FilipeZhou", function (assert) {
  1091. var done = assert.async(),
  1092. $fixture = $("#qunit-fixture");
  1093. $fixture.append('<input type="text" id="testmask" />');
  1094. var testmask = document.getElementById("testmask");
  1095. Inputmask("currency").mask(testmask);
  1096. testmask.focus();
  1097. $("#testmask").trigger("click");
  1098. setTimeout(function () {
  1099. $("#testmask").Type("1010");
  1100. $.caret(testmask, 3);
  1101. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  1102. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 10.00", "Result " + $("#testmask")[0].inputmask._valueGet());
  1103. done();
  1104. }, 0);
  1105. });
  1106. qunit.test("currency alias - type 1010 delete middle 1 - FilipeZhou", function (assert) {
  1107. var done = assert.async(),
  1108. $fixture = $("#qunit-fixture");
  1109. $fixture.append('<input type="text" id="testmask" />');
  1110. var testmask = document.getElementById("testmask");
  1111. Inputmask("currency").mask(testmask);
  1112. testmask.focus();
  1113. $("#testmask").trigger("click");
  1114. setTimeout(function () {
  1115. $("#testmask").Type("1010");
  1116. $.caret(testmask, 6);
  1117. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  1118. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 100.00", "Result " + $("#testmask")[0].inputmask._valueGet());
  1119. done();
  1120. }, 0);
  1121. });
  1122. qunit.test("currency alias - type -1234 delete -", function (assert) {
  1123. var done = assert.async(),
  1124. $fixture = $("#qunit-fixture");
  1125. $fixture.append('<input type="text" id="testmask" />');
  1126. var testmask = document.getElementById("testmask");
  1127. Inputmask("currency").mask(testmask);
  1128. testmask.focus();
  1129. $("#testmask").trigger("click");
  1130. setTimeout(function () {
  1131. $("#testmask").Type("-1234");
  1132. $.caret(testmask, 0);
  1133. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1134. assert.equal($("#testmask")[0].inputmask._valueGet(), "$ 1,234.00", "Result " + $("#testmask")[0].inputmask._valueGet());
  1135. done();
  1136. }, 0);
  1137. });
  1138. qunit.test("decimal alias - type 12345.12 add 6 in front - freeze - DatXN", function (assert) {
  1139. var $fixture = $("#qunit-fixture");
  1140. $fixture.append('<input type="text" id="testmask" />');
  1141. var testmask = document.getElementById("testmask");
  1142. Inputmask("decimal", {
  1143. integerDigits: 5,
  1144. digits: 2,
  1145. allowMinus: false,
  1146. allowPlus: false
  1147. }).mask(testmask);
  1148. testmask.focus();
  1149. $("#testmask").trigger("click");
  1150. $("#testmask").Type("12345.12");
  1151. $.caret(testmask, 0);
  1152. $("#testmask").SendKey("6");
  1153. assert.equal($("#testmask")[0].inputmask._valueGet(), "12345.12", "Result " + $("#testmask")[0].inputmask._valueGet());
  1154. });
  1155. qunit.test("decimal alias - type 123456789 - add , before 8 - jpontet", function (assert) {
  1156. var $fixture = $("#qunit-fixture");
  1157. $fixture.append('<input type="text" id="testmask" />');
  1158. var testmask = document.getElementById("testmask");
  1159. Inputmask("decimal", {
  1160. allowMinus: true,
  1161. integerDigits: 12,
  1162. digits: 2,
  1163. radixPoint: ",",
  1164. autoGroup: true,
  1165. groupSeparator: " ",
  1166. groupSize: 3,
  1167. rightAlign: false
  1168. }).mask(testmask);
  1169. testmask.focus();
  1170. $("#testmask").trigger("click");
  1171. $("#testmask").Type("123456789");
  1172. $.caret(testmask, 9);
  1173. $("#testmask").SendKey(",");
  1174. assert.equal($("#testmask")[0].inputmask._valueGet(), "1 234 567,89", "Result " + $("#testmask")[0].inputmask._valueGet());
  1175. });
  1176. qunit.test("decimal alias - type 123456789 - add , before 8 - backspace - jpontet", function (assert) {
  1177. var $fixture = $("#qunit-fixture");
  1178. $fixture.append('<input type="text" id="testmask" />');
  1179. var testmask = document.getElementById("testmask");
  1180. Inputmask("decimal", {
  1181. allowMinus: true,
  1182. integerDigits: 12,
  1183. digits: 2,
  1184. radixPoint: ",",
  1185. autoGroup: true,
  1186. groupSeparator: " ",
  1187. groupSize: 3,
  1188. rightAlign: false
  1189. }).mask(testmask);
  1190. testmask.focus();
  1191. $("#testmask").trigger("click");
  1192. $("#testmask").Type("123456789");
  1193. $.caret(testmask, 9);
  1194. $("#testmask").SendKey(",");
  1195. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  1196. assert.equal($("#testmask")[0].inputmask._valueGet(), "1 234 567,89", "Result " + $("#testmask")[0].inputmask._valueGet());
  1197. });
  1198. qunit.test("decimal alias - type 1234567890 - add , before 9 - jpontet", function (assert) {
  1199. var $fixture = $("#qunit-fixture");
  1200. $fixture.append('<input type="text" id="testmask" />');
  1201. var testmask = document.getElementById("testmask");
  1202. Inputmask("decimal", {
  1203. allowMinus: true,
  1204. integerDigits: 12,
  1205. digits: 2,
  1206. radixPoint: ",",
  1207. autoGroup: true,
  1208. groupSeparator: " ",
  1209. groupSize: 3,
  1210. rightAlign: false
  1211. }).mask(testmask);
  1212. testmask.focus();
  1213. $("#testmask").trigger("click");
  1214. $("#testmask").Type("1234567890");
  1215. $.caret(testmask, 11);
  1216. $("#testmask").SendKey(",");
  1217. assert.equal($("#testmask")[0].inputmask._valueGet(), "12 345 678,90", "Result " + $("#testmask")[0].inputmask._valueGet());
  1218. });
  1219. qunit.test("decimal alias - type 1234567890 - add , before 9 - backspace - jpontet", function (assert) {
  1220. var $fixture = $("#qunit-fixture");
  1221. $fixture.append('<input type="text" id="testmask" />');
  1222. var testmask = document.getElementById("testmask");
  1223. Inputmask("decimal", {
  1224. allowMinus: true,
  1225. integerDigits: 12,
  1226. digits: 2,
  1227. radixPoint: ",",
  1228. autoGroup: true,
  1229. groupSeparator: " ",
  1230. groupSize: 3,
  1231. rightAlign: false
  1232. }).mask(testmask);
  1233. testmask.focus();
  1234. $("#testmask").trigger("click");
  1235. $("#testmask").Type("1234567890");
  1236. $.caret(testmask, 11);
  1237. $("#testmask").SendKey(",");
  1238. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  1239. assert.equal($("#testmask")[0].inputmask._valueGet(), "12 345 678,90", "Result " + $("#testmask")[0].inputmask._valueGet());
  1240. });
  1241. qunit.test("numeric alias - value=\"-1234\" minvalue = 1000", function (assert) {
  1242. var $fixture = $("#qunit-fixture");
  1243. $fixture.append('<input type="text" id="testmask" value="-1234" />');
  1244. var testmask = document.getElementById("testmask");
  1245. Inputmask("numeric", {
  1246. allowMinus: true,
  1247. min: 1000,
  1248. max: 3000
  1249. }).mask(testmask);
  1250. testmask.blur();
  1251. assert.equal(testmask.inputmask._valueGet(), "1000", "Result " + testmask.inputmask._valueGet());
  1252. });
  1253. qunit.test("numeric alias - value=\"-1234\" minvalue = -1000", function (assert) {
  1254. var $fixture = $("#qunit-fixture");
  1255. $fixture.append('<input type="text" id="testmask" value="-1234" />');
  1256. var testmask = document.getElementById("testmask");
  1257. Inputmask("numeric", {
  1258. allowMinus: true,
  1259. min: -1000,
  1260. max: 3000
  1261. }).mask(testmask);
  1262. testmask.blur();
  1263. assert.equal(testmask.inputmask._valueGet(), "-1000", "Result " + testmask.inputmask._valueGet());
  1264. });
  1265. qunit.test("numeric alias - value=\"1000\" minvalue = 1000", function (assert) {
  1266. var $fixture = $("#qunit-fixture");
  1267. $fixture.append('<input type="text" id="testmask" value="1000" />');
  1268. var testmask = document.getElementById("testmask");
  1269. Inputmask("numeric", {
  1270. allowMinus: true,
  1271. min: 1000,
  1272. max: 3000
  1273. }).mask(testmask);
  1274. assert.equal($("#testmask")[0].inputmask._valueGet(), "1000", "Result " + $("#testmask")[0].inputmask._valueGet());
  1275. });
  1276. qunit.test("numeric alias - value=\"-1000\" minvalue = -1000", function (assert) {
  1277. var $fixture = $("#qunit-fixture");
  1278. $fixture.append('<input type="text" id="testmask" value="-1000" />');
  1279. var testmask = document.getElementById("testmask");
  1280. Inputmask("numeric", {
  1281. allowMinus: true,
  1282. min: -1000,
  1283. max: 3000
  1284. }).mask(testmask);
  1285. assert.equal($("#testmask")[0].inputmask._valueGet(), "-1000", "Result " + $("#testmask")[0].inputmask._valueGet());
  1286. });
  1287. qunit.test("decimal alias - overwrite decimal value - shahvaiz", function (assert) {
  1288. var $fixture = $("#qunit-fixture");
  1289. $fixture.append('<input type="text" id="testmask" />');
  1290. var testmask = document.getElementById("testmask");
  1291. Inputmask("decimal", {
  1292. autoGroup: true,
  1293. groupSeparator: ",",
  1294. suffix: '%'
  1295. }).mask(testmask);
  1296. $("#testmask").Type("123.123");
  1297. $.caret(testmask, 4, 7);
  1298. $("#testmask").Type("4");
  1299. assert.equal($("#testmask")[0].inputmask._valueGet(), "123.4%", "Result " + $("#testmask")[0].inputmask._valueGet());
  1300. });
  1301. qunit.test("numeric alias - placeholder: \"_\" - lucafik", function (assert) {
  1302. var done = assert.async(),
  1303. $fixture = $("#qunit-fixture");
  1304. $fixture.append('<input type="text" id="testmask" />');
  1305. var testmask = document.getElementById("testmask");
  1306. Inputmask("numeric", {
  1307. integerDigits: 2,
  1308. digits: 2,
  1309. placeholder: "_",
  1310. digitsOptional: false
  1311. }).mask(testmask);
  1312. testmask.focus();
  1313. $("#testmask").trigger("click");
  1314. setTimeout(function () {
  1315. $("#testmask").Type("12");
  1316. assert.equal($("#testmask")[0].inputmask._valueGet(), "12.__", "Result " + $("#testmask")[0].inputmask._valueGet());
  1317. done();
  1318. }, 0);
  1319. });
  1320. qunit.test("numeric alias - type 123.123 - delete all - ivodopyanov", function (assert) {
  1321. var done = assert.async(),
  1322. $fixture = $("#qunit-fixture");
  1323. $fixture.append('<input type="text" id="testmask" />');
  1324. var testmask = document.getElementById("testmask");
  1325. Inputmask("numeric").mask(testmask);
  1326. $("#testmask").trigger("click");
  1327. setTimeout(function () {
  1328. $("#testmask").Type("123.123");
  1329. $.caret(testmask, 0, testmask.value.length);
  1330. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1331. assert.equal($("#testmask")[0].inputmask._valueGet(), "", "Result " + $("#testmask")[0].inputmask._valueGet());
  1332. done();
  1333. }, 0);
  1334. });
  1335. qunit.test("currency alias - 123 - isvalid - ivodopyanov", function (assert) {
  1336. var done = assert.async(),
  1337. $fixture = $("#qunit-fixture");
  1338. $fixture.append('<input type="text" id="testmask" />');
  1339. var testmask = document.getElementById("testmask");
  1340. Inputmask("currency").mask(testmask);
  1341. $("#testmask").trigger("click");
  1342. setTimeout(function () {
  1343. $("#testmask").Type("123");
  1344. var isValid = Inputmask("currency").isValid(testmask.value);
  1345. assert.equal(isValid, true, "Result " + $(testmask).val() + " : " + isValid);
  1346. done();
  1347. }, 0);
  1348. });
  1349. qunit.test("currency alias - $ 99,999,999.00 - isvalid - ivodopyanov", function (assert) {
  1350. var $fixture = $("#qunit-fixture");
  1351. $fixture.append('<input type="text" id="testmask" />');
  1352. var testmask = document.getElementById("testmask");
  1353. Inputmask("currency").mask(testmask);
  1354. $("#testmask").Type("$ 99,999,999.00");
  1355. var isValid = Inputmask("currency").isValid(testmask.value);
  1356. assert.equal(isValid, true, "Result " + $(testmask).val() + " : " + isValid);
  1357. });
  1358. qunit.test("numeric alias - digits 2 type 0.12 - gharlan", function (assert) {
  1359. var $fixture = $("#qunit-fixture");
  1360. $fixture.append('<input type="text" id="testmask" value="0.12" />');
  1361. var testmask = document.getElementById("testmask");
  1362. Inputmask("numeric", {
  1363. digits: 2
  1364. }).mask(testmask);
  1365. $.caret(testmask, 0, 1);
  1366. $("#testmask").Type("1");
  1367. assert.equal($("#testmask")[0].inputmask._valueGet(), "1.12", "Result " + $("#testmask")[0].inputmask._valueGet());
  1368. });
  1369. qunit.test("numeric alias - digits 2 select 0 type 1 - gharlan", function (assert) {
  1370. var $fixture = $("#qunit-fixture");
  1371. $fixture.append('<input type="text" id="testmask" value="0.00" />');
  1372. var testmask = document.getElementById("testmask");
  1373. Inputmask("numeric", {
  1374. digits: 2
  1375. }).mask(testmask);
  1376. $.caret(testmask, 0, 1);
  1377. $("#testmask").Type("1");
  1378. assert.equal($("#testmask")[0].inputmask._valueGet(), "1.00", "Result " + $("#testmask")[0].inputmask._valueGet());
  1379. });
  1380. qunit.test("decimal alias - value 20,00 select 2 type 5 - schmulschubiak", function (assert) {
  1381. var $fixture = $("#qunit-fixture");
  1382. $fixture.append('<input type="text" id="testmask" value="20,00" />');
  1383. var testmask = document.getElementById("testmask");
  1384. Inputmask("decimal", {
  1385. radixPoint: ",",
  1386. autoGroup: true,
  1387. groupSeparator: " ",
  1388. groupSize: 3,
  1389. allowMinus: false,
  1390. digits: 2,
  1391. rightAlign: false
  1392. }).mask(testmask);
  1393. $.caret(testmask, 0, 1);
  1394. $("#testmask").Type("5");
  1395. assert.equal($("#testmask")[0].inputmask._valueGet(), "50,00", "Result " + $("#testmask")[0].inputmask._valueGet());
  1396. });
  1397. qunit.test("currency numericInput true - type 10020 - jaisonerick", function (assert) {
  1398. var done = assert.async(),
  1399. $fixture = $("#qunit-fixture");
  1400. $fixture.append('<input type="text" id="testmask" />');
  1401. var testmask = document.getElementById("testmask");
  1402. Inputmask("currency", {
  1403. allowPlus: false,
  1404. allowMinus: false,
  1405. rightAlign: false,
  1406. groupSeparator: '.',
  1407. radixPoint: ',',
  1408. numericInput: true,
  1409. digits: 2,
  1410. prefix: 'R$ ',
  1411. unmaskAsNumber: false
  1412. }).mask(testmask);
  1413. testmask.focus();
  1414. $("#testmask").trigger("click");
  1415. setTimeout(function () {
  1416. $("#testmask").Type("10020");
  1417. assert.equal($(testmask).val(), "R$ 100,20", "Result " + $(testmask).val());
  1418. done();
  1419. }, 0);
  1420. });
  1421. qunit.test("numeric - type 978-3498064365 - andreasba", function (assert) {
  1422. var $fixture = $("#qunit-fixture");
  1423. $fixture.append('<input type="text" id="testmask" />');
  1424. var testmask = document.getElementById("testmask");
  1425. Inputmask("numeric").mask(testmask);
  1426. $("#testmask").Type("978-3498064365");
  1427. assert.equal($(testmask).val(), "-9783498064365", "Result " + $(testmask).val());
  1428. });
  1429. qunit.test("numeric - type 978-3498064365 - andreasba", function (assert) {
  1430. var $fixture = $("#qunit-fixture");
  1431. $fixture.append('<input type="text" id="testmask" />');
  1432. var testmask = document.getElementById("testmask");
  1433. Inputmask("numeric", {
  1434. allowMinus: false
  1435. }).mask(testmask);
  1436. testmask.focus();
  1437. $("#testmask").Type("978-3498064365");
  1438. assert.equal($(testmask).val(), "9783498064365", "Result " + $(testmask).val());
  1439. });
  1440. qunit.test("currency alias - isvalid - ivodopyanov - htmlmasta", function (assert) {
  1441. var done = assert.async(),
  1442. $fixture = $("#qunit-fixture");
  1443. $fixture.append('<input type="text" id="testmask" />');
  1444. var testmask = document.getElementById("testmask");
  1445. Inputmask("currency").mask(testmask);
  1446. testmask.focus();
  1447. $("#testmask").trigger("click");
  1448. setTimeout(function () {
  1449. var i, isValid;
  1450. for (i = 0; i < 10; i++) {
  1451. $("#testmask").Type("9");
  1452. isValid = Inputmask("currency").isValid(testmask.value);
  1453. assert.equal(isValid, true, "Value: \"" + testmask.value + "\"; isValid: " + isValid);
  1454. }
  1455. done();
  1456. }, 0);
  1457. });
  1458. qunit.test("currency - goto last decimal place type 2", function (assert) {
  1459. var $fixture = $("#qunit-fixture");
  1460. $fixture.append('<input type="text" id="testmask" />');
  1461. var testmask = document.getElementById("testmask");
  1462. Inputmask("currency").mask(testmask);
  1463. testmask.focus();
  1464. $.caret(testmask, 5);
  1465. $("#testmask").Type("2");
  1466. assert.equal($(testmask).val(), "$ 0.02", "Result " + $(testmask).val());
  1467. });
  1468. qunit.test("decimal minvalue 0,3 - enter 0,2 - Aifz", function (assert) {
  1469. var $fixture = $("#qunit-fixture");
  1470. $fixture.append('<input type="text" id="testmask" />');
  1471. var testmask = document.getElementById("testmask");
  1472. Inputmask({
  1473. 'alias': 'decimal',
  1474. 'radixPoint': ',',
  1475. 'digits': '2',
  1476. 'min': '0,3',
  1477. 'max': '5',
  1478. 'allowMinus': false
  1479. }).mask(testmask);
  1480. testmask.focus();
  1481. $("#testmask").Type("0,2");
  1482. testmask.blur();
  1483. assert.equal($(testmask).val(), "0,3", "Result " + $(testmask).val());
  1484. });
  1485. qunit.test("currency max = 100 - type 200 - zigtechjs", function (assert) {
  1486. var $fixture = $("#qunit-fixture");
  1487. $fixture.append('<input type="text" id="testmask" />');
  1488. var testmask = document.getElementById("testmask");
  1489. Inputmask("percentage", {
  1490. placeholder: "_",
  1491. digitsOptional: false,
  1492. max: 100,
  1493. }).mask(testmask);
  1494. testmask.focus();
  1495. $("#testmask").Type("200");
  1496. testmask.blur();
  1497. assert.equal($(testmask).val(), "100.00 %", "Result " + $(testmask).val());
  1498. });
  1499. qunit.test("Numbers get swapped when cursor near suffix. #1278 - xklepio", function (assert) {
  1500. var $fixture = $("#qunit-fixture");
  1501. $fixture.append('<input type="text" id="testmask" />');
  1502. var testmask = document.getElementById("testmask");
  1503. Inputmask('decimal', {
  1504. radixPoint: ',',
  1505. groupSeparator: '.',
  1506. autoGroup: true,
  1507. repeat: 10,
  1508. digits: '2',
  1509. autoUnmask: true,
  1510. suffix: ' €'
  1511. }).mask(testmask);
  1512. testmask.focus();
  1513. $.caret(testmask, 1);
  1514. $("#testmask").Type("52");
  1515. assert.equal($("#testmask")[0].inputmask._valueGet(), "52 €", "Result " + $("#testmask")[0].inputmask._valueGet());
  1516. });
  1517. qunit.test("numeric + numericInput #1328 - douglasdtc", function (assert) {
  1518. var $fixture = $("#qunit-fixture");
  1519. $fixture.append('<input type="text" id="testmask" />');
  1520. var testmask = document.getElementById("testmask");
  1521. Inputmask("numeric", {
  1522. 'groupSeparator': '.',
  1523. 'groupSize': 3,
  1524. 'radixPoint': ',',
  1525. 'numericInput': true,
  1526. 'digits': 2
  1527. }).mask(testmask);
  1528. testmask.focus();
  1529. $("#testmask").val("237,38");
  1530. assert.equal(testmask.value, "237,38", "Result " + testmask.value);
  1531. });
  1532. qunit.test("numeric + type -", function (assert) {
  1533. var $fixture = $("#qunit-fixture");
  1534. $fixture.append('<input type="text" id="testmask" />');
  1535. var testmask = document.getElementById("testmask");
  1536. Inputmask("currency", {negationSymbol: {front: "(", back: ")"}}).mask(testmask);
  1537. testmask.focus();
  1538. $.caret(testmask, 1);
  1539. $("#testmask").Type("-");
  1540. assert.equal(testmask.value, "($ 0.00)", "Result " + testmask.value);
  1541. });
  1542. qunit.test("numeric + type 123 - select partial type 0", function (assert) {
  1543. var $fixture = $("#qunit-fixture");
  1544. $fixture.append('<input type="text" id="testmask" />');
  1545. var testmask = document.getElementById("testmask");
  1546. Inputmask("currency").mask(testmask);
  1547. testmask.focus();
  1548. $("#testmask").Type("123");
  1549. $.caret(testmask, 0, 5);
  1550. $("#testmask").Type("0");
  1551. assert.equal(testmask.inputmask._valueGet(), "$ 0.00", "Result " + testmask.inputmask._valueGet());
  1552. });
  1553. qunit.test("numeric + groupSeparator: \" \" backspace, - krajcot", function (assert) {
  1554. var $fixture = $("#qunit-fixture");
  1555. $fixture.append('<input type="text" id="testmask" />');
  1556. var testmask = document.getElementById("testmask");
  1557. Inputmask("currency", {
  1558. digits: 0,
  1559. groupSeparator: " ",
  1560. autoGroup: true
  1561. }).mask(testmask);
  1562. testmask.focus();
  1563. $("#testmask").Type("1");
  1564. $.caret(testmask, 3);
  1565. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  1566. assert.equal(testmask.inputmask._valueGet(), "$ 0", "Result " + testmask.inputmask._valueGet());
  1567. });
  1568. qunit.test("numeric + groupSeparator: \" \" delete, - krajcot", function (assert) {
  1569. var $fixture = $("#qunit-fixture");
  1570. $fixture.append('<input type="text" id="testmask" />');
  1571. var testmask = document.getElementById("testmask");
  1572. Inputmask("currency", {
  1573. digits: 0,
  1574. groupSeparator: " ",
  1575. autoGroup: true
  1576. }).mask(testmask);
  1577. testmask.focus();
  1578. $("#testmask").Type("1");
  1579. $.caret(testmask, 2);
  1580. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1581. assert.equal(testmask.inputmask._valueGet(), "$ 0", "Result " + testmask.inputmask._valueGet());
  1582. });
  1583. qunit.test("minvalue, - serGlazkov", function (assert) {
  1584. var $fixture = $("#qunit-fixture");
  1585. $fixture.append('<input type="text" id="testmask" />');
  1586. var testmask = document.getElementById("testmask");
  1587. Inputmask({
  1588. alias: 'integer',
  1589. autoUnmask: true,
  1590. rightAlign: false,
  1591. min: 18,
  1592. max: 80,
  1593. prefix: '',
  1594. suffix: ' %',
  1595. }).mask(testmask);
  1596. testmask.focus();
  1597. $("#testmask").Type("30");
  1598. $.caret(testmask, 1);
  1599. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1600. $("#testmask").Type("1");
  1601. assert.equal(testmask.inputmask._valueGet(), "31 %", "Result " + testmask.inputmask._valueGet());
  1602. });
  1603. qunit.test("groupseparator ' ' - krajcot", function (assert) {
  1604. var $fixture = $("#qunit-fixture");
  1605. $fixture.append('<input type="text" id="testmask" />');
  1606. var testmask = document.getElementById("testmask");
  1607. Inputmask("currency", {
  1608. groupSeparator: " ",
  1609. autoGroup: true,
  1610. suffix: " €",
  1611. prefix: "",
  1612. digits: 0,
  1613. inputEventOnly: false
  1614. }).mask(testmask);
  1615. testmask.focus();
  1616. testmask.blur();
  1617. assert.equal(testmask.inputmask._valueGet(), "0 €", "Result " + testmask.inputmask._valueGet());
  1618. });
  1619. qunit.test("decimal set 0.50", function (assert) {
  1620. var $fixture = $("#qunit-fixture");
  1621. $fixture.append('<input type="text" id="testmask" />');
  1622. var testmask = document.getElementById("testmask");
  1623. Inputmask("decimal", {
  1624. radixPoint: ',',
  1625. groupSeparator: '.',
  1626. autoGroup: true,
  1627. digits: 2,
  1628. removeMaskOnSubmit: false
  1629. }).mask(testmask);
  1630. $(testmask).val("0.50");
  1631. assert.equal(testmask.inputmask._valueGet(), "0,50", "Result " + testmask.inputmask._valueGet());
  1632. });
  1633. qunit.test("decimal set 1.000", function (assert) {
  1634. var $fixture = $("#qunit-fixture");
  1635. $fixture.append('<input type="text" id="testmask" />');
  1636. var testmask = document.getElementById("testmask");
  1637. Inputmask("decimal", {
  1638. radixPoint: ',',
  1639. groupSeparator: '.',
  1640. autoGroup: true,
  1641. digits: 2,
  1642. removeMaskOnSubmit: false
  1643. }).mask(testmask);
  1644. $(testmask).val("1.000");
  1645. assert.equal(testmask.inputmask._valueGet(), "1.000", "Result " + testmask.inputmask._valueGet());
  1646. });
  1647. qunit.test("decimal set 1234.56", function (assert) {
  1648. var $fixture = $("#qunit-fixture");
  1649. $fixture.append('<input type="text" id="testmask" />');
  1650. var testmask = document.getElementById("testmask");
  1651. Inputmask("decimal", {
  1652. radixPoint: ',',
  1653. groupSeparator: '.',
  1654. autoGroup: true,
  1655. digits: 2,
  1656. removeMaskOnSubmit: false
  1657. }).mask(testmask);
  1658. $(testmask).val("1234.56");
  1659. assert.equal(testmask.inputmask._valueGet(), "1.234,56", "Result " + testmask.inputmask._valueGet());
  1660. });
  1661. qunit.test("currency set 100.00 - NurGuz", function (assert) {
  1662. var $fixture = $("#qunit-fixture");
  1663. $fixture.append('<input type="text" id="testmask" />');
  1664. var testmask = document.getElementById("testmask");
  1665. Inputmask("currency", {radixPoint: ","}).mask(testmask);
  1666. $(testmask).val("100.00");
  1667. assert.equal(testmask.inputmask._valueGet(), "$ 100,00", "Result " + testmask.inputmask._valueGet());
  1668. });
  1669. qunit.test("decimal suffix: years => yers - marcelokohl", function (assert) {
  1670. var $fixture = $("#qunit-fixture");
  1671. $fixture.append('<input type="text" id="testmask" />');
  1672. var testmask = document.getElementById("testmask");
  1673. Inputmask('decimal', {
  1674. suffix: " years",
  1675. rightAlign: false,
  1676. onBeforeMask: function (value, opts) {
  1677. return value;
  1678. }
  1679. }).mask(testmask);
  1680. $(testmask).val("1");
  1681. assert.equal(testmask.inputmask._valueGet(), "1 years", "Result " + testmask.inputmask._valueGet());
  1682. });
  1683. qunit.test("decimal type 38700 delete 7 type 8 - Borzák Attila", function (assert) {
  1684. var $fixture = $("#qunit-fixture");
  1685. $fixture.append('<input type="text" id="testmask" />');
  1686. var testmask = document.getElementById("testmask");
  1687. Inputmask("decimal",
  1688. {autoGroup: true, groupSeparator: ","}).mask(testmask);
  1689. $(testmask).Type("38800");
  1690. $.caret(testmask, 3);
  1691. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1692. $("#testmask").Type("8");
  1693. assert.equal(testmask.inputmask._valueGet(), "38,800", "Result " + testmask.inputmask._valueGet());
  1694. });
  1695. qunit.test("decimal type 100. delete - Borzák Attila", function (assert) {
  1696. var $fixture = $("#qunit-fixture");
  1697. $fixture.append('<input type="text" id="testmask" />');
  1698. var testmask = document.getElementById("testmask");
  1699. Inputmask("decimal",
  1700. {autoGroup: true, groupSeparator: ","}).mask(testmask);
  1701. $(testmask).Type("100.");
  1702. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  1703. assert.equal(testmask.inputmask._valueGet(), "100", "Result " + testmask.inputmask._valueGet());
  1704. });
  1705. qunit.test("Currency digits and delete #1351 - kousenlsn", function (assert) {
  1706. var $fixture = $("#qunit-fixture");
  1707. $fixture.append('<input type="text" id="testmask" />');
  1708. var testmask = document.getElementById("testmask");
  1709. Inputmask( {
  1710. max: '99999999.99',
  1711. alias: 'currency',
  1712. prefix: '',
  1713. allowPlus: false,
  1714. autoUnmask: true}).mask(testmask);
  1715. $(testmask).Type("1.23");
  1716. $.caret(testmask, 0);
  1717. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1718. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1719. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  1720. assert.equal(testmask.inputmask._valueGet(), "0.00", "Result " + testmask.inputmask._valueGet());
  1721. });
  1722. };