Skip to content

Commit

Permalink
fix(textfield): add missing type attribute
Browse files Browse the repository at this point in the history
also fix required and add custom validation property

closes #210
  • Loading branch information
stasson committed Jan 16, 2018
1 parent 582adf0 commit fb796aa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
30 changes: 29 additions & 1 deletion components/textfield/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var vm = new Vue({
text: ""
}
})

```

### Help text
Expand Down Expand Up @@ -57,6 +56,9 @@ var vm = new Vue({
```

### Validation

- Native validation: use `type`, `required`, `minlength` and `maxlength` properties

```html
<mdc-textfield type="password" label="Password"
required minlength=8 maxlength=10
Expand All @@ -65,6 +67,31 @@ var vm = new Vue({
v-model="password" />
```

- Custom Validation: use `:valid` property:

```html
<mdc-textfield
:valid="isValid"
helptext="custom check"
helptext-persistent helptext-validation
v-model="value" />
```

```javascript
var vm = new Vue({
data: {
text: ""
}
computed: {
isValid () {
return myCustomCheck(this.text)
}
}
})
```

> Once set, native validition is ignored.
### props

| props | Type | default | Description |
Expand All @@ -81,6 +108,7 @@ var vm = new Vue({
|`required`| Boolean | | validation: whether this field is required|
|`minlength`| [Number, String] | | validation: minimal length|
|`maxlength`| [Number, String] | | validation: max length|
|`valid`| [Number, String] | | validation: custom validation property |
|`size`| [Number, String] | 20 | textfield size (chars) |
|`fullwidth`| Boolean | | whether the textfield is full width |
|`multiline`| Boolean | | whether the textfield is multiline |
Expand Down
20 changes: 18 additions & 2 deletions components/textfield/mdc-textfield.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

<custom-element ref="input"
:tag="inputTag"
:type="inputType"
:rows="inputRows"
:cols="inputCols"
:value="value" @input="updateValue($event.target.value)"
:class="inputClasses" :required="required"
:class="inputClasses"
:minlength="minlength" :maxlength="maxlength"
:placeholder="inputPlaceHolder"
:aria-label="inputPlaceHolder"
Expand Down Expand Up @@ -86,6 +87,7 @@ export default {
outline: Boolean,
disabled: Boolean,
required: Boolean,
valid: {type: Boolean, default: undefined},
minlength: { type: [Number, String], default: undefined },
maxlength: { type: [Number, String], default: undefined },
size: { type: [Number, String], default: 20 },
Expand Down Expand Up @@ -130,6 +132,14 @@ export default {
watch: {
disabled () {
this.foundation && this.foundation.setDisabled(this.disabled)
},
required () {
this.foundation && this.foundation.setRequired(this.disabled)
},
valid () {
if (typeof this.valid !== "undefined") {
this.foundation && this.foundation.setValid(this.valid)
}
}
},
methods: {
Expand All @@ -141,6 +151,9 @@ export default {
inputTag () {
return this.multiline ? 'textarea' : 'input'
},
inputType () {
return !this.multiline ? this.type : undefined
},
inputRows () {
return this.multiline ? this.rows : undefined
},
Expand Down Expand Up @@ -336,7 +349,10 @@ export default {
this.foundation.init()
this.foundation.setDisabled(this.disabled)
this.foundation.setRequired(this.required)
if (typeof this.valid !== "undefined") {
this.foundation.setValid(this.valid)
}
if (this.textbox) {
this.ripple = new RippleBase(this)
Expand Down
7 changes: 7 additions & 0 deletions components/unit-test/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,10 @@
}).call(this);


(function() {
// global HTMLInputElement
HTMLInputElement.prototype.validity = {
badInput: false,
valid: true,
}
}).call(this);

0 comments on commit fb796aa

Please sign in to comment.