Unable to activate style.display function in Vue JS color selector project

Currently wrapping up a project involving gradient swatches and moving on to the final stage of the republish function. I have two name forms: one is utilized in the initial creation of the swatch on keypress, while the other is intended for the edit function, triggered by a button click. However, the name is still being collected on enter as well. My goal is to hide the first form (which should not be used) and display the second form instead. The structure of the form is as follows:

 <b-form-input
        id="name"
        size="lg"
        type="text"
        class="search-bar-2"
        placeholder="Name Your Swatch, Enter Hit the Save Edit Button"
        v-model="value3"
        @keypress="republishSwatch"
        >
</b-form-input>

The republishSwatch method is also assigned to the click event of the save button. However, I am facing an issue where the code does not seem to recognize the class of the element "search-box-2". The objective is to display the edit button, which is functioning correctly, and toggle between hiding/showing the alternative forms. The first form has the same structure as above but with the class search-box-1. Even though they may need different ids due to the names.

   let oldForm = document.querySelector('.search-box-1');
   let newForm = document.querySelector('.search-box-2');
   let saveEditBtn = document.getElementById('saveBtn');
   saveEditBtn.style.display = 'block';
   oldForm.style.display = 'none';
   newForm.style.display = 'block';

In CSS, the second form is initially hidden using "display: none!important" since it requires important to ensure it hides properly. This is within Bootstrap Vue. If I manage to resolve this issue, I will likely consolidate the name collection into a single function and trigger it through the republish function via the button click.

Any advice or suggestions are greatly appreciated!

Thank you

Answer №1

For conditional rendering, it's recommended to use either v-show or v-if.

To show/hide fields based on a variable, you can set it inside your data and toggle its value.

<b-form-input
        id="name"
        size="lg"
        type="text"
        class="search-bar-2"
        placeholder="Name Your Swatch, Enter Hit the Save Edit Button"
        v-model="value3"
        @keypress="republishSwatch"
        v-show="shouldShow"
        >
</b-form-input>

Update the value of shouldShow from within an event listener on your button.

It's generally advised to avoid direct manipulation of the DOM in most cases.

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

An issue has arisen with AngularJS and Twitter Bootstrap, displaying an error message stating that the function element.focus

I recently implemented the angularjs twitter bootstrap datepicker and everything seemed to be working smoothly. However, I encountered an error when trying to click on the text box for the popup datepicker. This issue has left me puzzled as I am still new ...

Encountering a no-loops/no-loops eslint error in node.js code while attempting to utilize the for and for-of loops

While working on my nodejs application, I have encountered an issue with es-lint giving linting errors for using 'for' and 'for-of' loops. The error message states error loops are not allowed no-loops/no-loops. Below is the snippet of c ...

How can the backgroundImage css in react admin <Login /> be replaced using Material-UI?

I have been refering to the following resources: Learn about customizing login page background in React-Admin: Explore themes customization in Material-UI: https://material-ui.com/customization/components/ Instead of using a preset background, I want to ...

Use Javascript or jQuery to traverse a tree in postorder and generate HTML markup

I am looking to generate HTML code similar to the following: <ul> <li>Submenu 1 <ul> <li>Submenu 1.1</li> <li>Submenu 1.2 <ul> <li>Subm ...

Objects shifting position as the browser window is resized or zoomed

I've scoured through numerous examples, but none seem to work for my specific situation. On my webpage, I have multiple tables nested within a <div>, which serves as a background element (as it doesn't cover the entire screen). However, whe ...

Implementing a watcher property in JavaScript to dynamically add a class to an element

I'm currently facing an issue where I need to apply a class to an element when a certain data property changes. My approach involves using a watcher to monitor the value change and adding a class through JavaScript, as demonstrated in the code snippet ...

Why is my Bootstrap Carousel Switching Images but Refusing to Slide?

I've encountered a problem with my bootstrap carousel. The slide effect doesn't seem to be working, even though I have added the "slide" CSS tag. Instead of sliding, the images just quickly change without any transition. Here are some key points ...

Using JQuery to make a GET request and receive a JSON response, then selecting particular objects

I am in the process of developing a straightforward web application. The concept involves users inputting a license plate number, which will then connect to an OpenData API based on Socrata that houses information about all registered vehicles in my countr ...

Creating a feature in Angular JS that allows for each item in a list to be toggled individually

Looking for a more efficient way to toggle individual buttons without updating all at once? Check out this basic example where each button toggles independently by using ng-click="selected = !selected". Instead of updating all buttons at once, you can achi ...

Angularjs directive experiencing intermittent firing of IntersectionObserver

Currently, I am in the process of integrating lazy loading using the IntersectionObserver within my angularjs application. However, there seems to be an issue where the callback function of the observer is not always being triggered when scrolling up and ...

Angular 2 FileReader: A comprehensive guide

I have a situation where I need to upload an image in section X and pass the base 64 data of the uploaded image to section Y. But I am encountering some difficulties in section X HTML: <input type="file" id="hotspot" (change)="uploadHotSpot($event)"&g ...

How to display an array with JSON objects in Angular 4

Looking to display specific data from an array in my .html file that originates from my .ts file: myArray: ["03/05/2018", "2:54", "xoxo", "briefing", "your", [{ "Id": "1", "Time": "20:54", "Topic": "mmmmm", "GUEST1": { "Role": "HS" ...

Issue with manipulating currency conversion data

Currently, I am embarking on a project to develop a currency conversion application resembling the one found on Google's platform. The main hurdle I am facing lies in restructuring the data obtained from fixer.io to achieve a similar conversion method ...

What sets a module apart from a script?

As I delve into the depths of TypeScript documentation to grasp the concept of modules, particularly ES6 modules, I stumbled upon some interesting insights. typescript-modules - this documentation talks about typescript modules and highlights an important ...

Securing Confidential Information in Vue Data Storage

For the last month, I've dedicated my time to learning Vue. However, there's still one question that puzzles me: The web application I'm currently developing allows users to maintain daily diaries for different projects. They should be able ...

Guide on dividing and presenting ajax information into two separate div containers

I am attempting to showcase two sets of data on separate divs using ajax. Below is the code I am utilizing for this task. Here is the ajax implementation $(function () { $(".myBtn").click(function () { var id = $(this).data("id"); ...

Can you explain the distinction between 'ssr:false' and 'target:static' in NuxtJS?

When creating a static site with NuxtJS, it appears that there are 2 choices to make: setting either ssr:false or target:static in the NuxtJS configuration file (nuxt.config.js). Do these options essentially accomplish the same thing? Why are both availa ...

Dealing with errors when working with cross-domain JSONP requests in jQuery can be a

My attempts to capture a bad request error using my jquery code have been unsuccessful. $.get('http://example.com/', {}, function () {}, 'jsonp') .done(function () { // never fires }) .fail(function () { // never fires }) .a ...

Tips for implementing mongoDB regex in an Express application

Is there a way to use regex in MongoDB to filter results based on a specific query parameter in the URL? I attempted to use $regex syntax in the query.find() method but it did not provide the expected outcomes. Appreciate any help with this, thank you. C ...

Using JavaScript to submit the value of a checkbox

I'm currently working on a form submission using JavaScript that includes both text input and two checkboxes. <script> function SubmitFormData() { var preferredLocation = $("#preferred_location").val(); var relocation = []; ...