Skip to content

Commit e47d06b

Browse files
Make one-way-zip-code-mask component (#56)
1 parent f656fbb commit e47d06b

File tree

6 files changed

+82
-2
lines changed

6 files changed

+82
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ This component has the same interface as it's [ember-one-way-controls counterpar
7070
* [{{one-way-number-mask}}](docs/one-way-number-mask.md)
7171
* [{{one-way-phone-mask}}](docs/one-way-phone-mask.md)
7272
* [{{one-way-ssn-mask}}](docs/one-way-ssn-mask.md)
73+
* [{{one-way-zip-code-mask}}](docs/one-way-zip-code-mask.md)
7374

7475
## Input Mask Component (deprecated)
7576

@@ -253,7 +254,7 @@ than this tag, however.
253254

254255
Masks a US SSN code (`999-99-9999`).
255256

256-
### US ZIP Code Inputs
257+
### US ZIP Code Inputs (deprecated)
257258

258259
```hbs
259260
{{zip-code-input unmaskedValue=foo fullCode=false}}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import OneWayInputMask, { DEFAULT_NON_BOUND_PROPS } from 'ember-inputmask/components/one-way-input-mask';
2+
import { computed, get } from '@ember/object';
3+
4+
/**
5+
* `{{one-way-zip-code-mask}}` component.
6+
*
7+
* Displays an input that masks a US ZIP code.
8+
*
9+
* Future: Add config options that allow users to set locality
10+
* app wide.
11+
*
12+
* @param {boolean} fullCode Allows users to optionally enter the full ZIP+4 area code.e
13+
*/
14+
export default OneWayInputMask.extend({
15+
NON_ATTRIBUTE_BOUND_PROPS: DEFAULT_NON_BOUND_PROPS.concat('fullCode'),
16+
17+
/**
18+
* Allows users to optionally enter the full ZIP+4 area code.
19+
*/
20+
fullCode: false,
21+
22+
/**
23+
* @override
24+
*/
25+
mask: computed('fullCode', function() {
26+
if (get(this, 'fullCode')) {
27+
return '99999[-9999]';
28+
}
29+
30+
return '99999';
31+
}),
32+
});
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'ember-inputmask/components/one-way-zip-code-mask';

docs/one-way-zip-code-mask.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
One Way Zip Code Mask
2+
=====================
3+
4+
```
5+
{{one-way-zip-code-mask value update=(action (mut value))}}
6+
```
7+
8+
Masks a US ZIP code.
9+
10+
## Arguments
11+
12+
### fullCode
13+
14+
```
15+
{{one-way-zip-code-mask value fullCode=true update=(action (mut value))}}
16+
```
17+
18+
If `fullCode` is set to `true`, then it will enable the
19+
user to enter an extended ZIP+4 code.

tests/dummy/app/templates/application.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<fieldset>
3535
<legend>US Zip code input:</legend>
36-
{{zip-code-input}}
36+
{{one-way-zip-code-mask}}
3737
</fieldset>
3838

3939
<fieldset>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { moduleForComponent, test } from 'ember-qunit';
2+
import hbs from 'htmlbars-inline-precompile';
3+
import { fillIn, find } from 'ember-native-dom-helpers';
4+
5+
moduleForComponent('one-way-zip-code-mask', 'Integration | Component | one way zip code mask', {
6+
integration: true,
7+
8+
beforeEach() {
9+
this.set('update', unmaskedValue => {
10+
this.set('unmaskedValue', unmaskedValue);
11+
});
12+
},
13+
});
14+
15+
test('filled-in value', async function(assert) {
16+
this.render(hbs`{{one-way-zip-code-mask value=unmaskedValue update=update}}`);
17+
await fillIn('input', '12345');
18+
assert.equal(find('input').value, '12345');
19+
assert.equal(this.unmaskedValue, 12345);
20+
});
21+
22+
test('full code works', async function(assert) {
23+
this.render(hbs`{{one-way-zip-code-mask value=unmaskedValue fullCode=true update=update}}`);
24+
await fillIn('input', '123451234');
25+
assert.equal(find('input').value, '12345-1234');
26+
assert.equal(this.unmaskedValue, 123451234);
27+
});

0 commit comments

Comments
 (0)