Skip to content

Commit 774c6b1

Browse files
committed
[input, numeric, currency] added selectOnFocus prop
1 parent 732e16b commit 774c6b1

File tree

6 files changed

+98
-55
lines changed

6 files changed

+98
-55
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ export abstract class _InputBase extends FieldBase {
6565
* @default 'left'
6666
* @type {'left' | 'right' | string}
6767
*/
68-
@Prop()
69-
iconPos: 'left' | 'right' | string = 'left'
68+
@Prop({
69+
default: 'left'
70+
})
71+
iconPos: 'left' | 'right' | string
7072

7173
/**
7274
* Css class(es) applied to input component
@@ -78,4 +80,16 @@ export abstract class _InputBase extends FieldBase {
7880
})
7981
css: string
8082

83+
/**
84+
* Select text when receive focus
85+
*
86+
* @default true
87+
* @type {boolean}
88+
*/
89+
@Prop({
90+
type: Boolean,
91+
default: true
92+
})
93+
selectOnFocus: boolean
94+
8195
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export class Input extends _InputBase {
7474
// initiate value
7575
var target = $(this.$el).find('input').val(this.value)
7676

77+
if (this.selectOnFocus)
78+
target.on('focus', function () { $(this).select() })
79+
7780
// make up for validation
7881
Util.setDataValidateAttr(this, target)
7982
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"css": {
3232
"type": "string",
3333
"description": "Css class(es) applied to input component"
34+
},
35+
"select-on-focus": {
36+
"type": "boolean",
37+
"default": "true",
38+
"description": "Select text when receive focus"
3439
}
3540
}
3641
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,21 @@ export abstract class _NumericBase extends FieldBase {
9696
* @type {boolean}
9797
*/
9898
@Prop({
99-
type: Boolean
99+
type: Boolean,
100+
default: false
100101
})
101-
integer: boolean = false
102+
integer: boolean
103+
104+
/**
105+
* Select text when receive focus
106+
*
107+
* @default true
108+
* @type {boolean}
109+
*/
110+
@Prop({
111+
type: Boolean,
112+
default: true
113+
})
114+
selectOnFocus: boolean
102115

103116
}

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ export class Numeric extends _NumericBase {
4545
$(this.$el).find('input').autoNumeric('destroy');
4646
this.setupUI();
4747
}
48-
49-
48+
49+
5050
setupUI() {
5151
var def = this.$UI.$settings.numeric
5252

5353
var opt = {
5454
aDec: Util.pickNonEmpty(this.decimalSeparator, def.decimalSeparator),
55-
aSep: Util.pickNonEmpty(this.groupSeparator, def.groupSeparator),
55+
aSep: Util.pickNonEmpty(this.groupSeparator, def.groupSeparator),
5656
mDec: Util.pickNonEmpty(this.decimalPlaces, def.decimalPlaces),
5757
vMin: Util.pickNonEmpty(this.min, def.min),
5858
vMax: Util.pickNonEmpty(this.max, def.max)
@@ -64,12 +64,15 @@ export class Numeric extends _NumericBase {
6464
}
6565

6666
var target = $(this.$el).find('input')
67-
.autoNumeric('init', this.buildOptions(opt))
68-
.autoNumeric('set', this.value || 0).on('keyup change paste propertychange', (v) => {
69-
var value = $(v.target).autoNumeric('get')
70-
this.$emit('input', value)
71-
this.$emit('change', value)
72-
})
67+
.autoNumeric('init', this.buildOptions(opt))
68+
.autoNumeric('set', this.value || 0).on('keyup change paste propertychange', (v) => {
69+
var value = $(v.target).autoNumeric('get')
70+
this.$emit('input', value)
71+
this.$emit('change', value)
72+
})
73+
74+
if (this.selectOnFocus)
75+
target.on('focus', function () { $(this).select() })
7376

7477
Util.setDataValidateAttr(this, target)
7578
}
Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
11
{
2-
"base": {
3-
"FieldBase": "../../fields/field-base"
4-
},
5-
"props": {
6-
"name": {
7-
"type": "string",
8-
"description": "Input element name"
9-
},
10-
"placeholder": {
11-
"type": "string",
12-
"description": "Input element placeholder"
13-
},
14-
"value": {
15-
"type": "any",
16-
"description": "v-model binding"
17-
},
18-
"group-separator": {
19-
"type": "string",
20-
"description": "Thousands group separator"
21-
},
22-
"decimal-separator": {
23-
"type": "string",
24-
"description": "Decimal group separator"
25-
},
26-
"decimal-places": {
27-
"type": "number",
28-
"description": "Number of decimal places"
29-
},
30-
"min": {
31-
"type": "number",
32-
"description": "Minimum value allowed"
33-
},
34-
"max": {
35-
"type": "number",
36-
"description": "Maximum value allowed"
37-
},
38-
"integer": {
39-
"type": "boolean",
40-
"description": "Take only integer value",
41-
"default": "false"
42-
}
43-
}
2+
"base": {
3+
"FieldBase": "../../fields/field-base"
4+
},
5+
"props": {
6+
"name": {
7+
"type": "string",
8+
"description": "Input element name"
9+
},
10+
"placeholder": {
11+
"type": "string",
12+
"description": "Input element placeholder"
13+
},
14+
"value": {
15+
"type": "any",
16+
"description": "v-model binding"
17+
},
18+
"group-separator": {
19+
"type": "string",
20+
"description": "Thousands group separator"
21+
},
22+
"decimal-separator": {
23+
"type": "string",
24+
"description": "Decimal group separator"
25+
},
26+
"decimal-places": {
27+
"type": "number",
28+
"description": "Number of decimal places"
29+
},
30+
"min": {
31+
"type": "number",
32+
"description": "Minimum value allowed"
33+
},
34+
"max": {
35+
"type": "number",
36+
"description": "Maximum value allowed"
37+
},
38+
"integer": {
39+
"type": "boolean",
40+
"description": "Take only integer value",
41+
"default": "false"
42+
},
43+
"select-on-focus": {
44+
"type": "boolean",
45+
"default": "true",
46+
"description": "Select text when receive focus"
47+
}
48+
}
4449
}

0 commit comments

Comments
 (0)