Guide to creating a versatile bootstrap modal window in Vue.js

I need some assistance with creating a bootstrap modal window that provides a warning to the user before they take an action. The issue I am facing is that when I enter text into a field, close the modal, and then reopen it, the previous values are still there. How can I make the text field mandatory so that it clears when the modal is closed but retains the value in "reason"? Any guidance on this would be greatly appreciated!

Below is the code snippet using vuejs:

<div class="modal fade" id="reject" role="dialog">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Loan Rejection</h4>
        </div>
        <div class="modal-body">
          <p>Are you sure you want to reject this loan request?</p>
              
          <div class="form-group">
            <label>Reason: </label>
            <input v-model="reason" class="form-control" placeholder="Enter your reason">
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal" v-show="reason" @click="clearbox">Reject</button>
        </div>
      </div>
    </div>
</div>

</div>
</template>

<script type="text/javascript">
export default {
data () {
return {
loanRequest: '',
        reason: ''
}
},
    methods: {
      clearbox (){
        reason: ''
      }
    },
created () {
this.$http.get('http://localhost:9000/api/loans/hrvalidation')
.then(
response => {
this.loanRequest = response.body
})
.catch(function(error){
console.log(error)
})
}
}
</script>

Answer №1

Ensure to utilize this. in order to retrieve the value of reason within the method.

Check out this demonstration:

 data () {
    return {
        loanRequest: '',
        reason: ''
        }
 },
 methods: {
      clearbox (){
        console.log(this.reason);
        this.reason = null;
      }
 },

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

Adding a total row to a Vuetify datatable

Struggling to incorporate a totals row using this framework, but it doesn't seem to be supported out of the box. The workaround I've come up with doesn't quite hit the mark... <v-data-table :headers="headers" :items="desserts" ...

eliminating the __typename field from the urql query response prior to performing a mutation

When retrieving data from a GraphQL Server using urql, an additional _typename field is automatically included by urql to track the cache: { __typename "Book" name "test" description "the book" id "hPl3 ...

Ways to modify an object similar to manipulating an array collection

Hey there, I've heard that iterating and editing objects (not arrays) is not the best practice. Is there a more efficient way to do it as easily as it can be done with an array of objects? Check out this link for reference new Vue({ el: '#app ...

Excessive form inputs extend beyond the modal when utilizing Bootstrap 3

Having an issue loading a modal with Angular and populating it with a template. The main problem I'm facing is that the inputs are extending beyond the boundaries of the modal - attached below is a screenshot illustrating the problem: Below is the c ...

Prevent users from editing Dropdown List in Bootstrap Vue

I'm currently working on a project using "Bootstrap Vue" where I have implemented a feature that changes the input fields to readonly mode when the user clicks on the "confirm" button. This functionality is achieved through a boolean variable assigned ...

The combination of a modal box, checkbox, and cookie feature creates

I am trying to accomplish the following tasks: When the homepage loads, I want a modal box to appear Inside the modal box, there should be a form with a mandatory checkbox After checking the checkbox, submit the form and close the modal box to return to ...

Error encountered in Laravel API route: 'SymfonyComponentHttpKernelExceptionNotFoundHttpException' exception

As I work on creating a blog for my school project on my portfolio website, I am using VueJS and Laravel. To incorporate API routes into my project, it has become necessary. However, I encountered an issue when trying to delete a comment with a specific ID ...

Attempted to identify whether an item exists in an array, and if it does, then add the item to the array; if not, then perform

Allow me to make some clarifications as it might be a bit confusing initially. This project I'm working on is for school. I don't expect anyone to do it for me, but I need help with a specific part. I'm creating a simple shopping cart using ...

Ways to eliminate all content preceding a specified value

Currently utilizing Bootstrap Vue and aiming to incorporate a formatter callback for injecting HTML into a table column. In the provided example from Bootstrap's documentation, the link is formatted as an anchor link: Ex. <b-table striped respon ...

What is the process for computing two input values and placing the outcome in a different input field using Vue.js?

Check out my input fields below: <input v-model="form.sale_quantity" @change="computed" type="number" class="form-control" name="sale_quantity" id="sale_quantity" placeholder="Quantity&quo ...

Encountering an error while setting up a Vue app in WebStorm on a Mac. npm is throwing

I'm currently in the process of setting up a Vue App using WebStorm on my Mac. However, when I try to run the npm run dev command, I encounter the following error: npm ERR! missing script: dev Below is a snippet from my package.json file: "versio ...

What are the steps for implementing videojs vr in a Vue.js project?

After installing the videojs vr with npm install --save videojs-vr, I attempted to use it in my project: https://i.stack.imgur.com/lSOqF.png However, I encountered this error message: https://i.stack.imgur.com/QSe1g.png Any assistance would be greatly ...

The component's div does not respond to the max-width attribute

I'm currently facing an issue with my chart component in a view. I've been trying to reduce its size using max-width property but it doesn't seem to be working. Below are the relevant code snippets: <div id="chart"> < ...

Setting timeouts during Vue-cli unit testing can help improve the efficiency and accuracy of your tests

I have been running vue unit tests using the following command: vue-cli-service test:unit However, I am encountering an issue where some unit tests require a response from the server, causing them to take longer to execute. Is there a way for me to man ...

Retrieving specific data from nested arrays in Vue.js

I am currently working on Vue.js template development and facing an issue with filtering nested data in a faq section. When I try to add a search bar, the nested data array returns all data without proper filtering. Dom <v-container> <v ...

How to flip the value in v-model using VueJS

Below is the code snippet that I am working with: <input v-model="comb.inactive" type="checkbox" @click="setInactive(comb.id_base_product_combination)" > I am looking to apply the opposite value of comb.inactive to the v-model. Here are m ...

The challenge with custom events in Vue.js

I've been grappling with this issue for an extended period of time and I am at a loss as to what exactly is causing the problem with my vue custom events. <!-- within the vue template: main element --> <!-- not functioning <button @click= ...

ReactStrap: Difficulty concealing navbar item based on screen dimensions

Currently, I am referring to the official documentation to implement a scenario where a NavItem is only displayed for screen sizes greater than sm. As per the guidelines provided in the documentation, I have included the following attributes: https://i ...

vue-awesome-swiper / The button's name is synchronized, causing all other swiper elements to move in unison

<template> <swiper v-for="item in items" :key="item.id" :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback"> <swiper-slide>I'm Slide 1</swiper-slide> <swiper-slide>I'm Slide 2</swiper-slid ...

Adding URL path instead of overriding it

Could someone assist me with the dynamic routing while organizing pages in folders within Storyblok? Currently, I am facing an issue where the slug folder name is being appended to all the links displayed in the header. So, when a user clicks on a blog po ...