Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI - masked input onchange #6586

Merged
merged 3 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between the inner action (inside the parentheses) and outer action (inside the curly braces) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the outer one calls a curried version returned by the inner one, onChange just passes the value, but the inner one returns a curried setAndBroadcast with path already set.

/>

{{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}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the example code here got cut off! unfortunately this is one of the bugs with jsdoc2md -- it doesn't like it when components are on multiple lines. unfortunately you'll have to copy/paste the example from the component source file. womp. :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no :( I'll fit that, that's rather unfortunate though

@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