This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add number-input which optionally uses a sanitizer * Audit system for numeric inputs and use new component
- Loading branch information
1 parent
f8af165
commit 7c93e70
Showing
20 changed files
with
110 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import HTMLInput from 'ember-rapid-forms/components/html-input'; | ||
import layout from '../templates/components/html-input'; | ||
|
||
export default HTMLInput.extend({ | ||
layout, | ||
actions: { | ||
update(value) { | ||
let sanitize = this.get('mainComponent.sanitize'); | ||
if (sanitize && sanitize.call) { | ||
value = sanitize(value); | ||
} | ||
this.set('selectedValue', value); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Component.extend({ | ||
sanitizeFunction(value) { | ||
return value.replace(new RegExp(/([^0-9|.]+)/g), ''); | ||
}, | ||
tagName: '', | ||
actions: { | ||
sanitize(value) { | ||
return this.get('sanitizeFunction')(value); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{input | ||
type=mainComponent.type | ||
|
||
placeholder=mainComponent.placeholder | ||
value=(readonly selectedValue) | ||
name=mainComponent.name | ||
disabled=mainComponent.disabled | ||
class=(concat "form-control " mainComponent.elementClass) | ||
id=mainComponent.id | ||
required=mainComponent.required | ||
title=mainComponent.title | ||
pattern=mainComponent.pattern | ||
autofocus=mainComponent.autofocus | ||
readonly=mainComponent.readonly | ||
autoresize=mainComponent.autoresize | ||
input=(action "update" value="target.value") | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{em-input property=property label=label class=class sanitize=(action 'sanitize')}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import Ember from 'ember'; | ||
|
||
moduleForComponent('number-input', 'Integration | Component | number input', { | ||
integration: true | ||
}); | ||
|
||
test('the number-input renders', function(assert) { | ||
assert.expect(2); | ||
|
||
this.render(hbs` | ||
{{#em-form model=model}} | ||
{{number-input property='petType' label='Pet Type' class='test-number-input'}} | ||
{{/em-form}} | ||
`); | ||
|
||
assert.equal(this.$('label').text().trim(), 'Pet Type', 'it renders the label'); | ||
assert.ok(Ember.isPresent(this.$('.test-number-input')), 'it renders the input field'); | ||
}); | ||
|
||
test('the number input sanitizes the data', function(assert) { | ||
assert.expect(1); | ||
|
||
this.set('model', Ember.Object.create({ petType: 'cats' })); | ||
|
||
this.set('sanitizeFunction', (value) => { | ||
assert.equal(value, 'dragons', 'it passes the value to the sanitize function'); | ||
}); | ||
|
||
this.render(hbs` | ||
{{#em-form model=model}} | ||
{{number-input | ||
property='petType' | ||
sanitizeFunction=sanitizeFunction | ||
label='Pet Type' | ||
class='test-number-input'}} | ||
{{/em-form}} | ||
`); | ||
|
||
this.$('input').eq(0).val('dragons'); | ||
this.$('input').trigger('input'); | ||
this.$('input').trigger('change'); | ||
}); |