admin管理员组文章数量:1023221
I would like to implement an input field that can be unlocked by the user if needed.
Visually, I was thinking that the button should be either outside or inside the field but strongly linked to it.
To do so, I have been using the Vuetify Text Field's append-outer-icon
props :
The template :
<v-text-field
v-model="message"
:append-outer-icon="icon"
@click:append-outer="locked = !locked"
:disabled="locked"
></v-text-field>
And here is the script :
data: () => ({
message: '',
locked: true,
}),
puted: {
icon () {
return this.locked ? 'lock' : 'lock_open'
}
},
Here's the link to the Codepen :
However, the button cannot be clicked when the input is disabled.
Is there any way to have the button enabled while the input is not using this method or am I forced to separate the button and the input ?
I would like to implement an input field that can be unlocked by the user if needed.
Visually, I was thinking that the button should be either outside or inside the field but strongly linked to it.
To do so, I have been using the Vuetify Text Field's append-outer-icon
props :
The template :
<v-text-field
v-model="message"
:append-outer-icon="icon"
@click:append-outer="locked = !locked"
:disabled="locked"
></v-text-field>
And here is the script :
data: () => ({
message: '',
locked: true,
}),
puted: {
icon () {
return this.locked ? 'lock' : 'lock_open'
}
},
Here's the link to the Codepen : https://codepen.io/anon/pen/jQaJPK
However, the button cannot be clicked when the input is disabled.
Is there any way to have the button enabled while the input is not using this method or am I forced to separate the button and the input ?
Share Improve this question asked Nov 20, 2018 at 11:11 Thomas FerroThomas Ferro 2,45220 silver badges34 bronze badges2 Answers
Reset to default 5You can override the CSS which prevents icon's click events:
.v-input--is-disabled:not(.v-input--is-readonly) .v-icon.v-icon--disabled {
pointer-events: auto;
}
Or for additional customization you can put icon inside the append-outer
slot (there is also append
slot for "inner" HTML), add custom icon class and override CSS which prevents clicking.
<v-text-field
v-model="message"
:disabled="locked"
>
<v-icon
slot="append-outer"
@click="locked = !locked"
class="lock-button"
>
{{ icon }}
</v-icon>
</v-text-field>
So then also you can add color="black"
on v-icon
for example so it doesn't look disabled.
CSS:
.lock-button {
pointer-events: auto;
}
Codepen
i might be a little late, but i juste faced this problem, and what you were looking for is the prop readonly
<v-text-field
v-model="pseudo"
:readonly="!locked"
:append-icon="locked ? icon : icon2"
@click:append="appendIconClick"
/>
To anyone reading this, something like that will make the text input disabled until the icon is clicked
I would like to implement an input field that can be unlocked by the user if needed.
Visually, I was thinking that the button should be either outside or inside the field but strongly linked to it.
To do so, I have been using the Vuetify Text Field's append-outer-icon
props :
The template :
<v-text-field
v-model="message"
:append-outer-icon="icon"
@click:append-outer="locked = !locked"
:disabled="locked"
></v-text-field>
And here is the script :
data: () => ({
message: '',
locked: true,
}),
puted: {
icon () {
return this.locked ? 'lock' : 'lock_open'
}
},
Here's the link to the Codepen :
However, the button cannot be clicked when the input is disabled.
Is there any way to have the button enabled while the input is not using this method or am I forced to separate the button and the input ?
I would like to implement an input field that can be unlocked by the user if needed.
Visually, I was thinking that the button should be either outside or inside the field but strongly linked to it.
To do so, I have been using the Vuetify Text Field's append-outer-icon
props :
The template :
<v-text-field
v-model="message"
:append-outer-icon="icon"
@click:append-outer="locked = !locked"
:disabled="locked"
></v-text-field>
And here is the script :
data: () => ({
message: '',
locked: true,
}),
puted: {
icon () {
return this.locked ? 'lock' : 'lock_open'
}
},
Here's the link to the Codepen : https://codepen.io/anon/pen/jQaJPK
However, the button cannot be clicked when the input is disabled.
Is there any way to have the button enabled while the input is not using this method or am I forced to separate the button and the input ?
Share Improve this question asked Nov 20, 2018 at 11:11 Thomas FerroThomas Ferro 2,45220 silver badges34 bronze badges2 Answers
Reset to default 5You can override the CSS which prevents icon's click events:
.v-input--is-disabled:not(.v-input--is-readonly) .v-icon.v-icon--disabled {
pointer-events: auto;
}
Or for additional customization you can put icon inside the append-outer
slot (there is also append
slot for "inner" HTML), add custom icon class and override CSS which prevents clicking.
<v-text-field
v-model="message"
:disabled="locked"
>
<v-icon
slot="append-outer"
@click="locked = !locked"
class="lock-button"
>
{{ icon }}
</v-icon>
</v-text-field>
So then also you can add color="black"
on v-icon
for example so it doesn't look disabled.
CSS:
.lock-button {
pointer-events: auto;
}
Codepen
i might be a little late, but i juste faced this problem, and what you were looking for is the prop readonly
<v-text-field
v-model="pseudo"
:readonly="!locked"
:append-icon="locked ? icon : icon2"
@click:append="appendIconClick"
/>
To anyone reading this, something like that will make the text input disabled until the icon is clicked
本文标签: javascriptUntie text field39s icon click enabling from the input oneStack Overflow
版权声明:本文标题:javascript - Untie text field's icon click enabling from the input one - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745547385a2155458.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论