leveraging the v-modeled information from vue's two variables

When I v-model a data in my Vue HTML to validate it in my form, I also want to use it in another variable. Here is my HTML code:

<input class="input-style px-3" :class="{'border-red-error':v$.categoryTitle.$errors.length>0}" type="text"
            placeholder="title" :disabled="formIsSending" v-model="DataForValidating.categoryTitle">

However, my JavaScript code doesn't seem to be working:

const DataForValidating = reactive({
      categoryTitle: '',
      categorySlug: '',
    })

 const categoryFormData = {
      categoryTitle: DataForValidating.categoryTitle,
      categorySlug: DataForValidating.categorySlug,
    }

I tried making the categoryFormData reactive as well, but it's still not functioning as expected.

Answer №1

Utilize the @input event by passing a function and then saving the data in "DataForValidating.categoryTitle" to a different variable. Alternatively, you can use an arrow function directly in the @input event to assign the value of the v-model variable to another.

Answer №2

i received a response, now I must utilize a watcher

 watch:{
     'newCategoryData.categoryTitle': function (newVal){
      this.categoryFormData.categoryTitle=newVal
     },
     'newCategoryData.categorySlug': function (newVal){
      this.categoryFormData.categorySlug=newVal
     },
 }

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

Is there a way to send data to a sibling component without the need to store it as a variable?

In my project, I am utilizing bootstrap vue cards within a v-for loop. Within this loop, one of the tags is supposed to return a value based on the current iteration of v-for. My challenge is that when I save this value as a variable and pass it to another ...

Removing dropdown lists from input forms can be achieved without using jQuery by utilizing vanilla JavaScript

Looking to build a custom HTML/JavaScript terminal or shell. Interested in utilizing an input box and form to interact with JavaScript functions/commands. Unsure of how to eliminate the drop-down menu that appears after previous inputs. Pictured terminal: ...

Implementing CSS classes onto HTML elements following their retrieval from a database

Is there a way to add CSS classes to HTML tags when retrieving them from a database for a blog? For instance, if the database contains the following in a column named body: <p> SO is great </p> Then when outputting it in the View using s ...

Streamline the testing process to ensure compatibility with jQuery version 2.x

I currently have a substantial JavaScript code base that is all built on jQuery 1.8. I am planning to upgrade to jQuery 2.1 in the near future and I am fully aware that many parts of my code will likely break during this process. Is there any efficient me ...

AngularJS - Increase the input date by 6 hours before converting it to JSON

Is there a way to add 6 hours to an input date in AngularJS? I attempted the following code: var eventStart = new Date ($scope.event.startdateid); var startDate = new Date ( eventStart ); startDate.setHours ( eventStart.getHours() + 6 ); event.startdate ...

The Lerna command for adding packages fails with an error message stating that the packages are not related

Currently, I am utilizing lerna to manage a multirepo containing interrelated packages. This issue only arose after installing a new operating system. Whenever I attempt to utilize lerna add to add a dependency from one package to another, an error occurs ...

Adding a new property to a reactive object in VueJS 3: A simple guide

export default { setup() { const imageUrl = ref(""); const title = ref(""); const description = ref(""); var source = "Global"; const form = reactive({ title: "", descript ...

Exploring the power of async/await and promise in TypeScript

I'm puzzled as to why the return type string in this method is showing up as a red error: exportPageAsText(pageNumber: number): string { (async () => { const text = await this.pdfViewerService.getPageAsText(pageNumber); ...

Rules for specifying title attribute for tag a in JavaScript

What is the best way to handle conditions for the a tag (links) when it has content in the title attribute? If there is no description available, how should the script be used? For instance: if ( $('a').attr('title') == 'on any ...

Utilize the Same Function for Loading Ajax Content to Handle Additional Ajax Content

I am currently trying to load all the content on my site using ajax. The code below demonstrates how I am attempting to achieve this: <script> function lage(url){ $.get(url, function(data) { $('#plus').html(data); $('[hr ...

Node.js middleware for verifying required parameters

In my current application, I am utilizing node.js and express. I have developed multiple middleware functions, each one created in a similar fashion: function loadUser(req, res, next){ ... } I am interested in creating a middleware that can validate th ...

The PHP script encountered an issue with the HTTP response code while processing the AJAX contact form, specifically

Struggling to make this contact form function properly, I've tried to follow the example provided at . Unfortunately, all my efforts lead to a fatal error: "Call to undefined function http_response_code() in /hermes/bosoraweb183/b1669/ipg.tenkakletcom ...

PHP enables users to look at manual values in columns and MySQL values row by row

I have created a PHP program to organize seating arrangements for an exam hall. The user manually inputs the names of the halls, which should be displayed in columns in a table. The register numbers are fetched from a MySQL database and should be displayed ...

Verify whether a variable is empty or not, within the sequence flows in Camunda Modeler

When working with a sequenceFlow in a process instance, I need to check a condition that may involve a variable that has not been defined yet. I want the flow to proceed even if the variable is not defined, rather than throwing an ActivitiException. I hav ...

Pressing "Enter" initiates the submission of the form

My webpage contains a stylish GIF displayed as a button within a div. The script inside the div triggers a click event when the ENTER key is pressed, using $(this).click(). This click action has its own functionality. Everything functions smoothly in Fire ...

Tips for utilizing vulnerable web scripts on SSL-enabled pages

After implementing SSL to secure my pages, I encountered an issue where one of my scripts no longer functions properly. Specifically, I had a script on my page that was used to display the visit count from this website. Previously, it was functioning fla ...

Solving dependencies for npm modules

I have a project where I am utilizing a custom library to share Vue components across various applications. To achieve this, I have added my component library as an npm module and included it in the application's package.json file, which is functioni ...

Implementing updates to a website from a database without the need for a page refresh

I am eager to delve into the world of AJAX and have identified a seemingly straightforward challenge that I believe will serve as an informative learning experience. Imagine a scenario where users are continuously adding new entries to a database table. ...

Is it possible to modify the CSS of a single class when hovering over a child class of a different and unrelated class?

I am struggling with CSS combinators, especially when dealing with nested div, ul, and li elements. My issue involves changing the CSS of a div with the class "H" when hovering over li elements with the class "G". Since all of this is contained within a s ...

Production environment is facing issues with Laravel API routes, although they function properly in the development environment

I have developed my frontend using Vue 3 and the backend API in Laravel. Everything works smoothly on my local system, but when deployed to production, only the web routes function correctly while the API routes return a 404 error. Both the single-page app ...