Using `b-form-input` to toggle the visibility of the password using `v-bind:type`

Utilizing bootstrap.vue components, specifically "b-form-input", I am trying to implement a feature to hide and show the password by clicking the button attached to the input field. While this functionality works with a regular input field, I am facing challenges when using it with "b-form-input". The approach of using "v-bind:type=..." did not yield the desired results. How can I tackle this issue?

https://i.sstatic.net/NY9oW.png

https://i.sstatic.net/QEALZ.png

This is my current code:

<b-input-group>
  <input v-bind:type="[showPassword ? 'text' : 'password']">
  <b-input-group-append>
    <b-button @click="showPassword = !showPassword" size="sm" variant="outline-success">show</b-button>
  </b-input-group-append>
</b-input-group>

Update: Below is the updated code (quick and dirty implementation):

showPassword(){
  if (this.inputtype === "text") {
    this.inputtype = "password"
  }
  if (this.inputtype === "password") {
    this.inputtype = "text"
  }
  console.log("in show PW ... ")
},

HTML:

<b-input-group>
  <b-form-input :type="inputtype"
    :id="`type-${inputtype}`">
  </b-form-input>
  <b-input-group-append>
    <b-button @click="showPassword()"
      size="sm"
      variant="outline-success"
     >
        show
     </b-button>
    </b-input-group-append>
</b-input-group>

Answer №1

Check out this code snippet

<script>
export default {
  data() {
    return {
        displayPassword: false
     }
  }
}
</script>

<template>
  <div>
    Awesome input <input :type="displayPassword ? 'text' : 'password'">
    <button @click="displayPassword = !displayPassword">
      Toggle it
    </button>
  </div>
</template>

For a live demonstration


UPDATE: If you are using Nuxt2 with bootstrap-vue, here is the setup you need: https://github.com/kissu/so-input-bootstrap/blob/main/pages/index.vue#L13

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The md-select search filter currently functions according to the ng-value, but it is important for it to also

I am using a md select search filter with multiple options available. For instance: id: 133, label:'Route1' id: 144, label:'Route2' id: 155, label:'Route3' id: 166, label:'Route4' If I input '1' ...

What do cross-domain requests, cross-domain attacks, and cross-domain protocols entail?

Can anyone provide clarification on the concepts of cross domain requests, cross domain attacks, and cross domain protocols as they relate to the AJAX terminology? ...

Regex produces odd results in string processing

This particular JavaScript regular expression: homework.description = (homework.input.match(/((\(((\S\s?)\)?)*)|(about( \w*)*))/i)); When applied to the text: potato (potato) Produces this unexpected output: (potato),(potato), ...

Using Selenium Web Driver to extract information from Google's knowledge graph

Currently utilizing the Ruby Selenium web driver, my goal is to extract content from the Google Knowledge Graph located on the top right-hand side of the search results page. This element is within the <div class="xpdopen"> section. @driver = Seleni ...

Sticky positioning with varying column widths

How can I create HTML and CSS columns that stick together without manually specifying the "left:" parameter every time? The current example in the fiddle achieves what I want, but requires manual setting of the "left:" value. Is there a way to make this m ...

Connect Bootstrap Tabs to a pagination system (Backward Forward)

<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://m ...

What is the best way to create a regex pattern that can effectively split two consecutive mathematical operators ("/-", "*-") from a given string equation?

Struggling to convert a string equation into an array of numbers and operators, but having trouble getting it right. Here is the regex I've tried: Input: '1+2-33/45*78'.split(/([\+\-\*\/]+)/) Output: ["1", "+", "2", "- ...

Determining the query count in a MongoDB collection using Node.js

Exploring the world of MongoDb, I have embarked on a project to create a small phonebook application. This application allows users to add and remove entries with a name and phone number. While I have successfully implemented the functionality to add and d ...

Having trouble sending HTTP requests in Angular 6

I am currently facing an issue in my Angular application while trying to send an HTTP POST request to a Spring RESTful API. Despite my attempts, I have not been able to succeed and I do not see any error response in the browser console. Below is a snippet ...

Unable to transmit the checked value to the parent component from a custom checkbox component

Within my custom checkbox component, I am attempting to transfer the value of the checkbox form field to the parent component: <template> <div class="custom-checkbox"> <div :class="{ 'bg-white': value }"> <input ...

How to fetch files using URL in JavaScript

I need a solution for automatically downloading multiple PDF files from Google Drive and Docs using their URLs with JavaScript code. I don't want to manually go to each link to download the files. Although I've researched various answers on Stac ...

How to display the total of specific values on the screen using React

Looking to create an app that displays 9 boxes, each with 4 select options: close successful, close unsuccessful, callback, and open. The goal is to count the number of closed successful and unsuccessful boxes and display the total count at the top of the ...

What is the best way to notify administrator users when their accounts have exceeded the timeout period?

Working on the website for our high school newspaper, I've encountered a recurring issue on the admin page. Users are getting logged out after creating an article due to a time limit constraint. To address this problem, my goal is to implement an aler ...

What is the purpose of uploading the TypeScript declaration file to DefinitelyTyped for a JavaScript library?

After releasing two JavaScript libraries on npm, users have requested TypeScript type definitions for both. Despite not using TypeScript myself and having no plans to rewrite the libraries in TypeScript, I am interested in adding the type definition files ...

Tips for creating curved Extjs area and line charts with a gentle radius to soften the sharp curves

I have been working on a mixed charts component for Extjs, and I noticed that the curves appear too sharp. I am unable to find a configuration option to add radius to the curves. If anyone has experience with this issue, could you please share a method t ...

Importing a JSON file into a JavaScript script

let jsonData ; $.getJSON("../data.json",function(response){ jsonData = response; }); Despite using $.getJSON() from jQuery, I am consistently getting null data in return. The JSON file path is confirmed to be accurate, but the issue persists. ...

"Utilizing an if-else statement within a forEach loop

I have an array of ages and I want to determine the age range for each age along with the count, then push it into my object. The issue I am facing is that if there are multiple ages in the same range, it gets pushed twice. I only want to push it once and ...

exploring the realm of creating constants in AngularJS functions

controller.js angular.module('app.main') .controller('MainCtrl', function ($scope, currentUser, addAPI) { $scope.form = {}; $scope.subdomain = currentUser.domainName; $scope.add = function () { addAPI.addAdmin(loc ...

What is the best approach to removing a component by utilizing the children prop in React?

I am currently working on a specific scenario: In my project, I have a component called Foo with a property named bar If the bar property is set to true, then I need to display the Bar component that is nested inside the Foo component If the bar prop ...

Adjust the size of the div to fit its content while maintaining the transition animation

I am aiming for the DIV height to automatically adjust to the text within it, while also maintaining a minimum height. However, when the user hovers their mouse over the DIV, I want the height to change smoothly without losing the transition effect. When ...