Skip to content

Commit 3fb98a1

Browse files
Clean up k-textbox
1 parent 467466b commit 3fb98a1

File tree

14 files changed

+164
-64
lines changed

14 files changed

+164
-64
lines changed

kolibri/core/assets/src/views/k-textbox/index.vue

Lines changed: 92 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<template>
22

33
<ui-textbox
4-
@focus="$emit('focus')"
5-
@blur="$emit('blur')"
6-
@input="updateText"
7-
@keydown="emitKeydown"
4+
ref="textbox"
85
v-model="currentText"
9-
:disabled="disabled"
10-
:placeholder="placeholder"
116
:label="label"
127
:aria-label="ariaLabel"
13-
:autocomplete="autocomplete"
14-
:autofocus="autofocus"
8+
:disabled="disabled"
159
:required="required"
16-
:type="type"
17-
:error="error"
1810
:invalid="invalid"
11+
:error="invalidText"
12+
:autofocus="autofocus"
1913
:maxlength="maxlength"
20-
:enforceMaxlength="enforceMaxlength"
21-
ref="textbox"
14+
:autocomplete="autocomplete"
15+
:type="type"
16+
:enforceMaxlength="true"
17+
:floatingLabel="true"
18+
@input="updateText"
19+
@keydown="emitKeydown"
20+
@focus="$emit('focus')"
21+
@blur="$emit('blur')"
2222
/>
2323

2424
</template>
@@ -33,53 +33,112 @@
3333
*/
3434
export default {
3535
name: 'k-textbox',
36+
components: { uiTextbox },
3637
props: {
37-
disabled: { type: Boolean },
38-
autofocus: { type: Boolean },
39-
required: { type: Boolean },
40-
invalid: { type: Boolean },
38+
/**
39+
* v-model
40+
*/
4141
value: {
4242
type: [String, Number],
4343
},
44-
error: { type: String },
45-
placeholder: { type: String },
46-
label: { type: String },
44+
/**
45+
* Label
46+
*/
47+
label: {
48+
type: String,
49+
required: true,
50+
},
51+
/**
52+
* Aria label
53+
*/
4754
ariaLabel: {
4855
type: String,
4956
// enforcing accessibility
50-
required: !!this.label,
57+
required: true,
5158
},
52-
autocomplete: { type: String },
53-
type: { type: String },
54-
maxlength: { type: Number },
55-
enforceMaxlength: {
59+
/**
60+
* Whether or not disabled
61+
*/
62+
disabled: {
5663
type: Boolean,
57-
default: true,
64+
default: false,
65+
},
66+
/**
67+
* Whether or not required
68+
*/
69+
required: {
70+
type: Boolean,
71+
default: false,
72+
},
73+
/**
74+
* Whether or not input is invalid
75+
*/
76+
invalid: {
77+
type: Boolean,
78+
default: false,
79+
},
80+
/**
81+
* Text displayed if input is invalid
82+
*/
83+
invalidText: {
84+
type: String,
85+
required: false,
86+
},
87+
/**
88+
* Whether or not to autofocus
89+
*/
90+
autofocus: {
91+
type: Boolean,
92+
default: false,
93+
},
94+
/**
95+
* Max allowed length of input
96+
*/
97+
maxlength: {
98+
type: Number,
99+
required: false,
100+
},
101+
/**
102+
* HTML5 autocomplete attribute (off, on, name, username, current-password, etc.)
103+
*/
104+
autocomplete: {
105+
type: String,
106+
required: false,
107+
},
108+
/**
109+
* HTML5 type of input (text, password, number, etc.)
110+
*/
111+
type: {
112+
type: String,
113+
default: 'text',
58114
},
59115
},
60116
data() {
61117
return { currentText: this.value };
62118
},
119+
watch: {
120+
value(val) {
121+
this.currentText = val;
122+
},
123+
},
63124
methods: {
64-
updateText(text) {
125+
updateText() {
126+
// v-model is just a :value + @input
65127
/**
66-
* v-model is just a :value + @input
128+
* Emits input event with new value
67129
*/
68130
this.$emit('input', this.currentText);
69131
},
70132
reset() {
71133
this.$refs.textbox.reset();
72134
},
73135
emitKeydown(e) {
136+
/**
137+
* Emits keydown event with event
138+
*/
74139
this.$emit('keydown', e);
75140
},
76141
},
77-
watch: {
78-
value(val) {
79-
this.currentText = val;
80-
},
81-
},
82-
components: { uiTextbox },
83142
};
84143
85144
</script>

kolibri/plugins/coach/assets/src/views/create-exam-page/index.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
<k-textbox
88
:label="$tr('title')"
99
:ariaLabel="$tr('title')"
10-
:placeholder="$tr('enterTitle')"
1110
:autofocus="true"
1211
:invalid="titleInvalid"
13-
:error="titleInvalidMsg"
12+
:invalidText="titleInvalidMsg"
1413
v-model.trim="inputTitle"
1514
@blur="validateTitle = true"
1615
@input="validateTitle = true"
@@ -20,9 +19,8 @@
2019
<k-textbox
2120
:label="$tr('numQuestions')"
2221
:ariaLabel="$tr('numQuestions')"
23-
:placeholder="$tr('enterNum')"
2422
:invalid="numQuestionsInvalid"
25-
:error="numQuestionsInvalidMsg"
23+
:invalidText="numQuestionsInvalidMsg"
2624
type="number"
2725
v-model.trim.number="inputNumQuestions"
2826
@blur="validateNumQuestMax = true"
@@ -34,7 +32,6 @@
3432
<h2>{{ $tr('chooseExercises') }}</h2>
3533
<!--<k-textbox-->
3634
<!--:ariaLabel="$tr('searchContent')"-->
37-
<!--:placeholder="$tr('searchContent')"-->
3835
<!--v-model.trim="searchInput"-->
3936
<!--/>-->
4037
<!--<div v-if="searchInput">-->
@@ -150,9 +147,7 @@
150147
chooseExercises: 'Select exercises to pull questions from',
151148
selectAll: 'Select all',
152149
title: 'Exam title',
153-
enterTitle: 'Enter a title',
154150
numQuestions: 'Number of questions',
155-
enterNum: 'Enter a number',
156151
examRequiresTitle: 'The exam requires a title',
157152
numQuestionsBetween: 'The exam requires a number of questions between 1 and 50',
158153
numQuestionsExceed:

kolibri/plugins/coach/assets/src/views/exams-page/rename-exam-modal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:autofocus="true"
99
:required="true"
1010
:invalid="duplicateTitle"
11-
:error="$tr('duplicateTitle')"
11+
:invalidText="$tr('duplicateTitle')"
1212
v-model.trim="newExamTitle"/>
1313
<div class="footer">
1414
<k-button :text="$tr('cancel')" :raised="false" type="button" @click="close"/>

kolibri/plugins/coach/assets/src/views/groups-page/create-group-modal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:autofocus="true"
1111
:required="true"
1212
:invalid="duplicateName"
13-
:error="$tr('duplicateName')"
13+
:invalidText="$tr('duplicateName')"
1414
v-model.trim="groupNameInput" />
1515
<k-button :text="$tr('cancel')"
1616
@click="close"

kolibri/plugins/coach/assets/src/views/groups-page/rename-group-modal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:autofocus="true"
1111
:required="true"
1212
:invalid="duplicateName"
13-
:error="$tr('duplicateName')"
13+
:invalidText="$tr('duplicateName')"
1414
v-model.trim="groupNameInput" />
1515
<k-button :text="$tr('cancel')"
1616
:raised="false"

kolibri/plugins/management/assets/src/views/class-edit-page/class-rename-modal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
:autofocus="true"
1414
:required="true"
1515
:invalid="duplicateName"
16-
:error="$tr('duplicateName')"
16+
:invalidText="$tr('duplicateName')"
1717
type="text"
1818
/>
1919

kolibri/plugins/management/assets/src/views/manage-class-page/class-create-modal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
:autofocus="true"
1414
:required="true"
1515
:invalid="duplicateName"
16-
:error="$tr('duplicateName')"
16+
:invalidText="$tr('duplicateName')"
1717
type="text"
1818
/>
1919

kolibri/plugins/management/assets/src/views/manage-content-page/wizard-import-network.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@back="goBack"
1111
>
1212
<div class="main">
13-
<k-textbox :label="$tr('enterContentChannel')" v-model="channelId" :disabled="wizardState.busy"/>
13+
<k-textbox :label="$tr('enterContentChannel')" ariaLabel="$tr('enterContentChannel')" v-model="channelId" :disabled="wizardState.busy"/>
1414
</div>
1515
<div class="core-text-alert">
1616
{{ wizardState.error }}
@@ -41,8 +41,8 @@
4141
export default {
4242
name: 'wizardImportNetwork',
4343
$trs: {
44-
title: 'Please choose a source...',
45-
enterContentChannel: 'Please enter a content channel ID:',
44+
title: 'Import from the internet',
45+
enterContentChannel: 'Content channel ID',
4646
cancel: 'Cancel',
4747
import: 'Import',
4848
},

kolibri/plugins/management/assets/src/views/user-page/user-create-modal.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,36 @@
1111
<section>
1212
<k-textbox
1313
:label="$tr('name')"
14+
:ariaLabel="$tr('name')"
1415
:autofocus="true"
1516
:required="true"
1617
:maxlength="120"
17-
:enforceMaxlength="true"
1818
type="text"
1919
class="user-field"
2020
v-model.trim="fullName"/>
2121
<k-textbox
2222
:label="$tr('username')"
23+
:ariaLabel="$tr('username')"
2324
:required="true"
2425
:maxlength="30"
25-
:enforceMaxlength="true"
2626
:invalid="usernameInvalid"
27-
:error="usernameInvalidMsg"
27+
:invalidText="usernameInvalidMsg"
2828
type="text"
2929
class="user-field"
3030
v-model="username"/>
3131
<k-textbox
3232
:label="$tr('password')"
33+
:ariaLabel="$tr('password')"
3334
:required="true"
3435
type="password"
3536
class="user-field"
3637
v-model="password"/>
3738
<k-textbox
3839
:label="$tr('reEnterPassword')"
40+
:ariaLabel="$tr('reEnterPassword')"
3941
:required="true"
4042
:invalid="passwordConfirmInvalid"
41-
:error="$tr('pwMismatchError')"
43+
:invalidText="$tr('pwMismatchError')"
4244
type="password"
4345
class="user-field"
4446
v-model="passwordConfirm"/>

kolibri/plugins/setup_wizard/assets/src/views/index.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@
2020
@focus="firstUsernameFieldVisit || visitUsername()"
2121
@blur="validateUsername()"
2222
:invalid="!!usernameError"
23-
:error="usernameError"
23+
:invalidText="usernameError"
2424
:required="true"
2525
:label="$tr('usernameInputLabel')"
26+
:ariaLabel="$tr('usernameInputLabel')"
2627
:maxlength="30"
27-
:enforceMaxlength="true"
2828
v-model="username"
2929
/>
3030

3131
<k-textbox
3232
@focus="firstPasswordFieldsVisit || visitPassword()"
3333
:invalid="!!passwordError"
34-
:error="passwordError"
34+
:invalidText="passwordError"
3535
:required="true"
3636
:label="$tr('passwordInputLabel')"
37+
:ariaLabel="$tr('passwordInputLabel')"
3738
type="password"
3839
v-model="password"
3940
/>
@@ -43,6 +44,7 @@
4344
:invalid="!!passwordError"
4445
:required="true"
4546
:label="$tr('reEnterPasswordInputLabel')"
47+
:ariaLabel="$tr('reEnterPasswordInputLabel')"
4648
type="password"
4749
v-model="passwordConfirm"
4850
/>
@@ -59,11 +61,11 @@
5961
@focus="firstFacilityFieldVisit || visitFacility()"
6062
@blur="validateFacility"
6163
:invalid="!!facilityError"
62-
:error="facilityError"
64+
:invalidText="facilityError"
6365
:required="true"
6466
:label="$tr('facilityInputLabel')"
67+
:ariaLabel="$tr('facilityInputLabel')"
6568
:maxlength="100"
66-
:enforceMaxlength="true"
6769
v-model="facility"
6870
/>
6971
</fieldset>

0 commit comments

Comments
 (0)