From 54f4345e6ac464feca8bde746621346062910b78 Mon Sep 17 00:00:00 2001 From: Bethany Seeger Date: Tue, 17 Oct 2023 11:25:13 -0400 Subject: [PATCH] This adds `postfix` capabilities to both Money and Number Inputs. Co-Authored-By: Lauren Kemperman; lkemperman@codeforamerica.org --- README.md | 49 +++++++++++------- readme-assets/money-input-with-postfix.png | Bin 0 -> 6038 bytes readme-assets/number-input-with-postfix.png | Bin 0 -> 5109 bytes .../templates/fragments/inputs/money.html | 3 +- .../templates/fragments/inputs/number.html | 29 ++++++----- 5 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 readme-assets/money-input-with-postfix.png create mode 100644 readme-assets/number-input-with-postfix.png diff --git a/README.md b/README.md index df15bedbb..63b01173f 100644 --- a/README.md +++ b/README.md @@ -862,32 +862,33 @@ A convenience live template for text area inputs is provided through `cfa:inputT ### Number Number inputs are used to gather numbers from users. The number input makes use -of `inputmode="numeric"` -which -will cause mobile devices to display the number pad when entering values into the input. The number -input -is useful for gathering numbers that don't already have a specific input type, such as the phone, -money, -date or SSN inputs. +of `inputmode="numeric"` which will cause mobile devices to display the number pad when entering +values into the input. The number input is useful for gathering numbers that don't already have a +specific input type, such as the phone, money, date or SSN inputs. Number inputs have an optional `title` parameter, which when passed will set the `title` attribute -on the input -The text given for the title will be displayed as a tooltip when the user hovers over the input as -well as in -client-side HTML based validation errors. The default title if one is not passed will +on the input The text given for the title will be displayed as a tooltip when the user hovers over +the input as well as in client-side HTML based validation errors. The default title if one is not +passed will be `Please make sure you are entering a positive, whole number or decimal value with 2 decimal places.` Number inputs also have an optional `pattern` parameter which represents a regex pattern that must -be met for the input to be valid. -The default regex pattern is `^\d*(\.\d{0,2})?$` which allows for any positive number with up to 2 -decimal places. +be met for the input to be valid. The default regex pattern is `^\d*(\.\d{0,2})?$` which allows for +any positive number with up to 2 decimal places. A different pattern can be passed if you wish to change this default behavior. If you change -the `pattern` -make sure you also change the `title` to represent your new pattern. +the `pattern` make sure you also change the `title` to represent your new pattern. Number inputs have an optional `placeholder` parameter. -A convenience live template for numbers is provided through `cfa:inputNumber`. +Number inputs have an optional `postfix` parameter. When set, this will put the passed in string at +the end of the number input, like so: + +image of number input with postfix message + +In this `postfix` example, the string passed in was "hrs". The string will not get submitted with +the input data and is only shown in the user interface. + +A live template for numbers is provided through `cfa:inputNumber`. ### Social Security Number @@ -937,10 +938,18 @@ Money inputs are used to gather monetary values. Visually, they are displayed as a dollar sign `$` prefixed in front of the input. Money inputs have an optional `placeholder` parameter. -We also provide a convenience validator for money inputs, `@Money` -which validates that entered values are valid monetary values. +Money inputs have an optional `postfix` parameter. When set, this will put the passed in string at +the end of the money input, like so: + +image of money input with postfix message + +In this `postfix` example, the string passed in was "/hr". The string will not get submitted with +the input data and is only shown in the user interface. + +We also provide a validator for money inputs, `@Money`, which validates that entered +values are valid monetary values. -A convenience live template for money inputs is provided through `cfa:inputMoney`. +A live template for money inputs is provided through `cfa:inputMoney`. ### Phone diff --git a/readme-assets/money-input-with-postfix.png b/readme-assets/money-input-with-postfix.png new file mode 100644 index 0000000000000000000000000000000000000000..870b22ff0b2387270607b3ba4ff3ad743f544546 GIT binary patch literal 6038 zcmeHLc{r5o-yd6+EE8F>PLw4XBKsJ!D_bH8p+aI7W-zifgqDNSLdkZtl09ZJ7?YxO zvL3PxgG#osl%=t~&kWA#`n}hCz1RES`@4SUxvu-Ux9@U4pYQki-rxJa=4fvvz$eKE z0)YfDs7Sw)#kJif&bq3Ed7^2Up#VB*I-5Ohw05W+x+E%~vrTH$-Bgfi$ zz}7eC!-`K{3>_X`)q5B@)4*mh^#H7|dO3=6bMD0vC@$a~9L=&%>n- zsJ`0$(=qr7rRlne0KCv&Y}997ySK={a^KHeQ+6+x?~ApJRV|dr{JB`{>=S_RYZ$lM zy$h$2tn%jhkw40EHoj9X!GE*knKC`gvFE(c?8&PsCW0#S{CsW0@##}d%1XJH)~Q~d z{bUZsY@T#G)cOuRW7>q09qPhwg?BE8oVwt&642#TCf3Oo8}BLn?UL?C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M4FARWM zxAM|ywCb2Hy*E<_!N9|1LV9ctWeS^d_8qBe4%3p{Xi&MpQ3IDt;5 z2kZ7AiXEe{)xIC@mHM}4mty~LxU8M}{lTULQyK|XlKAONj7s$nbEz4f9ehZEYxAvf z?hy?tE)udor@M}&Llc0#C*ec7dg_i>^3M>|YV8+pW%4i1)Ec}vRpEEEl3$*6hROnG z&>Km~k-LBOFS`5VPUr|H3m=US?449x_&rpKSh~o7LFpfH?%ZvjtQ76&&YIPc7WCT6 zOuj*_)zD6I?O66R2ZbCU`)>^!Xns4BCT5JNywEOh3^6WF<6!w#Iwx{%9@Dcr)!D9Q zS2c$`?51!Hpuci_*QPcyS8>#ui(aYmU_Q1yIed&@?eC{V3~i*kuwtvpV@?K~0f}Oy zlC73ty^W-H@8o^#aqhyF7MqT;DwgrSk@VgDkyZt;+EID|Q>#g?6Z>1;qo|>38S3{* z1+qh5SC{BQz-Qn9G|woo-#$txLWukGov*Sm219PT0*Uivp#kexhL}L^1Izr)X)kM; zz;W{o8%3?8WP&9g*wxPii_kopz*+<#AOgrAYw8NNPfcmS(dxaj=qBVqvhh~%d8XS&k2s)l7zP`?ueKce`A}y?lj6Jk-NCY34wDN7T*C8YA8hj+j&I({gS_iy zy6qAZ@@-|blj7drx9>9k;KDn_j_Qaj(qy;2C=|Hvm?-b~x^r7 Cs!T@! literal 0 HcmV?d00001 diff --git a/readme-assets/number-input-with-postfix.png b/readme-assets/number-input-with-postfix.png new file mode 100644 index 0000000000000000000000000000000000000000..0f173b42f3b5cea3d9accd920571039c779e91b5 GIT binary patch literal 5109 zcmeHKXH-*L7EWje5RD3AL-T@Ch44T?LJN|h2oVC(9w4Gdh!`SCDAFYO6a~eg2nq;@ zbOc9K0#6ZmwjffZOG1-4^xpeiQh2VJAM<1W%$hZKt&?-^+27vh?7hEp?#@l?6Gx>a zc1eIhASv@>Xd4hnhzyLMLd1aI)oUg_AQ0G@U}|b@ZfXj%CX>z+F5*ETr5GZ;)FK?W z@WCscP|}I3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{CnH=oEM1i z(GOh;uQlv$EbkN@mGiqLuJz`rAn8yDz#kA!z^y`nh)xO_RsteIJ+XAj5M@E0MLyzA zTN=yjMu#8|@re70t~HRf&jAtFTiNQQDXvR#XpQS z5`axmbV=B8frr}xLsjWh0`R{H$A94Jig0vj=lQ)}$JxODc91#d1iIkJ>F|F5h{8zp literal 0 HcmV?d00001 diff --git a/src/main/resources/templates/fragments/inputs/money.html b/src/main/resources/templates/fragments/inputs/money.html index 17651a768..e1f8b2bfb 100644 --- a/src/main/resources/templates/fragments/inputs/money.html +++ b/src/main/resources/templates/fragments/inputs/money.html @@ -26,8 +26,9 @@ aria-labelledby=${hasAriaLabel ? ariaLabel : ''}, aria-invalid=${hasError}" th:value="${fieldData.getOrDefault(inputName, '')}"> +
- \ No newline at end of file + diff --git a/src/main/resources/templates/fragments/inputs/number.html b/src/main/resources/templates/fragments/inputs/number.html index 3ac697562..a4038cf3e 100644 --- a/src/main/resources/templates/fragments/inputs/number.html +++ b/src/main/resources/templates/fragments/inputs/number.html @@ -17,19 +17,22 @@ th:if="${hasHelpText}" th:id="${inputName + '-help-text'}" th:text="${helpText}">

- +
+ +
+
- \ No newline at end of file +