Skip to content

Commit

Permalink
UI - masked input onchange (#6586)
Browse files Browse the repository at this point in the history
* update masked-input to work with form-field component

* add test for masked input onChange functionality

* fix doc changes
  • Loading branch information
meirish committed Apr 15, 2019
1 parent 339d2a9 commit 8f44742
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
10 changes: 6 additions & 4 deletions ui/app/components/masked-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import autosize from 'autosize';
* `MaskedInput` components are textarea inputs where the input is hidden. They are used to enter sensitive information like passwords.
*
* @example
* ```js
* <MaskedInput
* @value={{attr.options.defaultValue}}
* @placeholder="secret"
* @allowCopy={{true}}
* @onChange={{action "someAction"}}
* />
* ```
*
* @param [value] {String} - The value to display in the input.
* @param [placeholder=value] {String} - The placeholder to display before the user has entered any input.
* @param [allowCopy=null] {bool} - Whether or not the input should render with a copy button.
* @param [displayOnly=false] {bool} - Whether or not to display the value as a display only `pre` element or as an input.
* @param [onChange=Function.prototype] {Function|action} - A function to call when the value of the input changes.
*
*
*/

Expand Down Expand Up @@ -63,8 +64,9 @@ export default Component.extend({
this.toggleProperty('isMasked');
},
updateValue(e) {
this.set('value', e.target.value);
this.onChange();
let value = e.target.value;
this.set('value', value);
this.onChange(value);
},
},
});
1 change: 1 addition & 0 deletions ui/app/templates/components/form-field.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
@value={{or (get model valuePath) attr.options.defaultValue}}
@placeholder=""
@allowCopy="true"
@onChange={{action (action "setAndBroadcast" valuePath)}}
/>

{{else if (or (eq attr.type "number") (eq attr.type "string"))}}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/masked-input.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="masked-input {{if shouldObscure "masked"}} {{if displayOnly "display-only"}} {{if allowCopy "allow-copy"}}" data-test-masked-input>
<div class="masked-input {{if shouldObscure "masked"}} {{if displayOnly "display-only"}} {{if allowCopy "allow-copy"}}" data-test-masked-input data-test-field>
{{#if displayOnly}}
<pre class="masked-value display-only is-word-break">{{displayValue}}</pre>
{{else}}
Expand Down
13 changes: 7 additions & 6 deletions ui/stories/masked-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
| [placeholder] | <code>String</code> | <code>value</code> | The placeholder to display before the user has entered any input. |
| [allowCopy] | <code>bool</code> | <code></code> | Whether or not the input should render with a copy button. |
| [displayOnly] | <code>bool</code> | <code>false</code> | Whether or not to display the value as a display only `pre` element or as an input. |
| [onChange] | <code>function</code> \| <code>action</code> | <code>Function.prototype</code> | A function to call when the value of the input changes. |

**Example**

```js
<MaskedInput
@value={{attr.options.defaultValue}}
@placeholder="secret"
@allowCopy={{true}}
/>
<MaskedInput
@value={{attr.options.defaultValue}}
@placeholder="secret"
@allowCopy={{true}}
@onChange={{action "someAction"}}
/>
```


**See**

Expand Down
5 changes: 4 additions & 1 deletion ui/tests/integration/components/form-field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ module('Integration | Component | form field', function(hooks) {
});

test('it renders: sensitive', async function(assert) {
await setup.call(this, createAttr('password', 'string', { sensitive: true }));
let [model, spy] = await setup.call(this, createAttr('password', 'string', { sensitive: true }));
assert.ok(component.hasMaskedInput, 'renders the masked-input component');
await component.fields[0].textarea('secret');
assert.equal(model.get('password'), 'secret');
assert.ok(spy.calledWith('password', 'secret'), 'onChange called with correct args');
});

test('it uses a passed label', async function(assert) {
Expand Down

0 comments on commit 8f44742

Please sign in to comment.