Skip to content

Commit

Permalink
fix: add required rule
Browse files Browse the repository at this point in the history
  • Loading branch information
14nrv committed Oct 24, 2020
1 parent 70fdd7b commit d6f6dc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/Fields/Control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export default {
},
getRules () {
const { rules = {}, pattern } = this.item
rules.required = this.item.isRequired !== false
let validation
pattern && (validation = { regex: new RegExp(pattern) })
return { ...rules, ...validation }
Expand Down
7 changes: 7 additions & 0 deletions src/components/Form/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ describe('Form', () => {
expect($inputSubmit).toHaveAttribute('disabled', 'disabled')
})

it('has submit btn disabled if no default value in field', async () => {
await wrapper.setProps({ formFields: [{ label: 'a label' }] })
await flush()

expect($inputSubmit).toHaveAttribute('disabled', 'disabled')
})

it('enables submit input if all fields are valid', async () => {
await flush()
expect($inputSubmit).toHaveAttribute('disabled', 'disabled')
Expand Down

0 comments on commit d6f6dc0

Please sign in to comment.