Experiencing a Problem with Vue Form Input Bindings when Using Conditional Binding

Could someone provide assistance with adding a condition to this Binding that outputs different bindings depending on the number of commas in the input?

<p>{{ target}}</p>
<input v-model="target" placeholder="Enter Your Target" />

If there are no commas, the output should be:

You Entered `London`

If there is one comma:

You Entered `London` AND `Paris`

If there are many commas:

You Entered `London` AND `Paris` AND `Rome`

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

Answer №1

Maybe similar to this:

new Vue({
  el: '#app',
  data() {
    return {
      item: '',
    }
  },
  computed: {
    displayItem() {
      return this.item && '`' + this.item.replaceAll(".", "` OR `") + '`'
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <p>You selected {{ displayItem }}</p>
  <input v-model="item" placeholder="Select an Item" />
</div>

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

AngularJS: Utilize the ngStyle directive to add styling to a specific child

I'm trying to style an embedded svg file within a span using ng-style based on its index. Can anyone help me figure out how to do this? <li ng-repeat="menuItem in menuItems" class="menuitem" ng-class="{'smenuitem': ($index === menuselect ...

Stop and resume CSS animation when the user hovers over and leaves

Can you share some insights on how to pause and resume a CSS transition? Check out the code below: animationstate = "running"; function animate() { if (animationstate == "running") { deskppssystemdiv.style.transitionDuration = "2000ms"; ...

Using Ionic with React to smoothly scroll to a selected item in a list

Ionic Scroll To Specific List Item covers Ionic + Angular. However, the solution provided is tailored to AngularJS. Now, I have a similar question but related to Ionic + React: Assuming a layout like this: <IonContent> <IonList> <Io ...

Nuxt.js - Which specific files and directories are required for deploying the production version on a hosting platform?

Visit this link for more information I am facing a challenge in deploying Nuxt to live hosting as there seems to be no clear indication of the required files. When using Nuxt CLI, it generates empty folders like: - assets - components - layouts - ...

The entire DOM refreshes when a user updates the input field

In my React component, I am managing two states: inputText and students. The inputText state tracks the value of an input field, while the students state is an array used to populate a list of student names. The issue arises when the inputText state change ...

"Doubling Up: The Art of Adding Elements to a Polymer

I am currently working on a to-do application using Polymer 2.0. One issue I'm facing is that when I add a note, it adds it as expected. However, when I try to add another note, it duplicates the notes in the array. I am having difficulty pinpointing ...

Instructions on filling the star icon with color upon clicking the button

Currently working on a project using codeIgniter where I have a form for rating products. I am facing an issue where, upon clicking the star button, only the border color changes to yellow while the center of the button remains white. Can someone please g ...

Error: Invalid argument type. The argument "chunk" should be either a string or a Buffer, instead of a number

Currently, I am working on a problem on HackerEarth and utilizing JavaScript for the task. Here is the code I have implemented: // Sample code to perform I/O: process.stdin.resume(); process.stdin.setEncoding("utf-8"); var stdin_input = ""; process.stdin ...

What is causing my Three.js scene to appear pitch black?

I am embarking on my first three.js project, but unfortunately my scene is appearing entirely black. I am utilizing Vite as my local server. Below is the JavaScript code I am currently using: import * as THREE from 'three' //Scene const scene = ...

Linking a Kendo widget to an HtmlHelper component through JavaScript in MVC/Razor

I am currently working on integrating an MVC ListBoxFor control with a Kendo MultiSelectFor to bind and update data. The goal is to have a list of users in the ListBox, and a list of available users in the MultiSelect box. When users are selected from the ...

Insert a new row in a table using jQuery

Could you help me figure out how to move an element within a table row into another table using jQuery? I've been considering using 'append', but it requires session handling. What is the best method in this case: should I use ajax, JSON, PH ...

VueJs fails to update data in certain situations

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <div class="container" id="app"> <table> <tr v-for="res in results" > <td> <input :id=res.id :value=res.LinkTitle > </td> ...

Update the state within a callback to display corresponding content in a React component

Struggling with rendering conditional content based on the presence of a value. In my component, if an API key is not provided, I want to display an input field with a button. Once the API key is stored using `electron-json-storage` and set as a state, the ...

Java Entity Framework Indexing Tables

I am currently utilizing ASP.Net Core and have implemented EntityFramework to create a controller with views. Specifically, I am in the process of enhancing the Index view to make it dynamic with dropdown selections. I have successfully completed everythin ...

How to import an HTML file using TypeScript

I need to load an html file located in the same directory as the typescript file and return it from the function. public ...(... ) : angular.IHttpPromise<string> { ... return $http({ method: 'GET', url: &apos ...

Tips for positioning the title of a card in Bootstrap-Vue

I'm currently working with the <b-card> component from bootstrap-vue and encountering an issue where I am unable to center align the title property. Does anyone have a solution for this problem? Below you can find the structure of my card, which ...

What could be causing the lack of updates in my shared service across all components?

I have implemented an Angular2 app where I am initializing an authentication service called LocalStorage which I want to be accessible across all my components: bootstrap(AppComponent, [ ROUTER_PROVIDERS, LocalStorage ]); The definition of the Lo ...

Creating a multitude of cubes by iterating through the pixel color data of getImageData in Three.js

Using a simple 3x3.png file to extract color/opacity data from, where each of the 9 pixels represents a different color/opacity level. The .png is supposed to be loaded onto an off-screen canvas, following which the 9 cubes are drawn in a 3x3 grid pattern ...

JavaScript basic calculator app failed to generate an error as anticipated

For my homework assignment, I am developing a basic calculator application using JavaScript. My main task is to ensure that the input numbers are limited to only two and that they are valid numbers; otherwise, an error should be thrown. Initially, concern ...

Sending data between Angular and Python using both strings and JSON formats

Seeking assistance with a Python script that sends events to a server. Here is the code snippet: LOGGER = logging.getLogger("send_event") POST_EVENT_URL = "http://localhost:3000/event/" def send(name, data): url = POST_EVENT_URL + name headers = {& ...