Skip to content

Commit 7b3bdc0

Browse files
committed
[form] add keyboard-shortcuts prop
1 parent fa342a5 commit 7b3bdc0

File tree

8 files changed

+84
-5
lines changed

8 files changed

+84
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ui-form v-on:success="submit" label-width="100px" :validator="validator" :keyboard-shortcuts="false">
2+
<ui-message class="info">
3+
Form not submitted until you press <strong>Submit</strong> button
4+
</ui-message>
5+
<ui-input kind="inline" label="First Name" placeholder="Please enter first name" v-model="firstName"></ui-input>
6+
<ui-input kind="inline" label="Last Name" placeholder="Please enter last name" v-model="lastName"></ui-input>
7+
<ui-button class="submit positive">Submit</ui-button>
8+
9+
<ui-message class="error"></ui-message>
10+
</ui-form>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component } from 'vue-typed'
2+
import * as Vue from 'vue'
3+
import { Base } from '../../base'
4+
5+
@Component({ template: require('./index.html') })
6+
export class FormDisableKeyboardShortcuts extends Base {
7+
firstName: string = ''
8+
lastName: string = ''
9+
10+
validator = {
11+
firstName: {
12+
identifier: 'firstName',
13+
rules: [{ type: 'empty', prompt: 'First name can not be empty' }]
14+
},
15+
lastName: {
16+
identifier: 'lastName',
17+
rules: [{ type: 'empty', prompt: 'Last name can not be empty' }]
18+
}
19+
}
20+
21+
submit() {
22+
this.$ui.toast.success('Changes saved!')
23+
}
24+
}

demo/src/demo/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FormBasic } from './form/basic';
22
import { FormInline } from './form/inline';
33
import { FormVariations } from './form/variations';
4+
import { FormDisableKeyboardShortcuts } from './form/disable-keyboard-shortcuts';
45
import { FormComponentBasic } from './form-component/basic';
56
import { FormComponentReplace } from './form-component/replace';
67
import { InputBasic } from './input/basic';
@@ -30,6 +31,7 @@ const m = [
3031
{ group: 'component/form', text: 'Form Basic', path: 'form/basic', component: FormBasic },
3132
{ group: 'component/form', text: 'Inline Form', path: 'form/inline', component: FormInline },
3233
{ group: 'component/form', text: 'Variations', path: 'form/variations', component: FormVariations },
34+
{ group: 'component/form', text: 'Disable Keyboard Shortcuts', path: 'form/disable-keyboard-shortcuts', component: FormDisableKeyboardShortcuts },
3335
{ group: 'decorator/form', text: 'Basic', path: 'form-component/basic', component: FormComponentBasic },
3436
{ group: 'decorator/form', text: 'Replace', path: 'form-component/replace', component: FormComponentReplace },
3537
{ group: 'component/input', text: 'Basic Input', path: 'input/basic', component: InputBasic },

dist/vue-typed-ui.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,17 @@ var _FormBase = function (_Vue) {
296296

297297
function _FormBase() {
298298
classCallCheck(this, _FormBase);
299-
return possibleConstructorReturn(this, (_FormBase.__proto__ || Object.getPrototypeOf(_FormBase)).apply(this, arguments));
299+
300+
/**
301+
* Adds keyboard shortcut for enter key to submit form
302+
*
303+
* @default true
304+
* @type {boolean}
305+
*/
306+
var _this = possibleConstructorReturn(this, (_FormBase.__proto__ || Object.getPrototypeOf(_FormBase)).apply(this, arguments));
307+
308+
_this.keyboardShortcuts = true;
309+
return _this;
300310
}
301311

302312
return _FormBase;
@@ -309,6 +319,9 @@ __decorate([vueTyped.Prop({
309319
__decorate([vueTyped.Prop({
310320
type: String
311321
})], _FormBase.prototype, "labelWidth", void 0);
322+
__decorate([vueTyped.Prop({
323+
type: Boolean
324+
})], _FormBase.prototype, "keyboardShortcuts", void 0);
312325

313326
var Form = function (_FormBase2) {
314327
inherits(Form, _FormBase2);
@@ -328,7 +341,9 @@ var Form = function (_FormBase2) {
328341
},
329342
onFailure: function onFailure(formErrors, fields) {
330343
self.$emit('error', formErrors, fields);
331-
}
344+
},
345+
// using default form keyboard shortcuts instead
346+
keyboardShortcuts: false
332347
};
333348
if (this.validator) {
334349
Object.assign(opt, {
@@ -353,7 +368,8 @@ var Form = function (_FormBase2) {
353368
}, {
354369
key: 'render',
355370
value: function render(ch) {
356-
return ch('form', {
371+
var tag = this.keyboardShortcuts ? 'form' : 'div';
372+
return ch(tag, {
357373
class: 'ui form',
358374
domProps: {
359375
onsubmit: function onsubmit(e) {

doc/api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@
475475
"type": "component",
476476
"readme": false,
477477
"props": {
478+
"keyboard-shortcuts": {
479+
"type": "boolean",
480+
"description": "Adds keyboard shortcut for enter key to submit form",
481+
"default": "true"
482+
},
478483
"label-width": {
479484
"type": "string",
480485
"description": "Width of fields label when displayed 'inline'."

src/components/form-inputs/form/_base.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,15 @@ export abstract class _FormBase extends Vue {
3636
})
3737
labelWidth: string
3838

39+
/**
40+
* Adds keyboard shortcut for enter key to submit form
41+
*
42+
* @default true
43+
* @type {boolean}
44+
*/
45+
@Prop({
46+
type: Boolean
47+
})
48+
keyboardShortcuts: boolean = true
49+
3950
}

src/components/form-inputs/form/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export class Form extends _FormBase {
1414
},
1515
onFailure: function (formErrors, fields) {
1616
self.$emit('error', formErrors, fields)
17-
}
17+
},
18+
19+
// using default form keyboard shortcuts instead
20+
keyboardShortcuts: false
1821
};
1922

2023
if (this.validator) {
@@ -42,7 +45,10 @@ export class Form extends _FormBase {
4245
}
4346

4447
render(ch) {
45-
return ch('form', {
48+
49+
let tag = this.keyboardShortcuts ? 'form' : 'div'
50+
51+
return ch(tag, {
4652
class: 'ui form',
4753
domProps: {
4854
onsubmit: function onsubmit(e) {

src/components/form-inputs/form/schema/props.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"label-width": {
1515
"type": "string",
1616
"description": "Width of fields label when displayed 'inline'."
17+
},
18+
"keyboard-shortcuts": {
19+
"type": "boolean",
20+
"description": "Adds keyboard shortcut for enter key to submit form",
21+
"default": "true"
1722
}
1823
}
1924
}

0 commit comments

Comments
 (0)