Restrict the character count in Vue Material chips

Currently, I am utilizing the Vue Material Chips component to gather string arrays. My goal is to limit the character length of each string within the array to 30 characters.

The component offers a md-limit prop which restricts the number of strings in the array but does not control the character count per string.

It seems like implementing a custom validation before adding each string to the array will be necessary since using v-validate did not yield the desired effect on the chips component.

If anyone has any suggestions on how I can accomplish this, it would be greatly appreciated! Thank you.

Answer №1

After reviewing the process

  1. You currently store an array of chips (for example:
    this.fruits = ['Banana','Apple','Pineapple','SomeOtherFruitWithMoreThan30Chars']
    )
  2. Upon pressing enter, the v-model variable is updated and appends your input to the array

Here's my approach:

  1. Implement a deep watch (a regular one might suffice)
watch: {
  fruits:{
    // newVal represents the new value of the array
    handler: function(newVal) {

      //checks if the last element of the array exceeds 30 characters
      if(newVal[(newVal.length - 1)].length > 30){
        //remove the last element of the array
        this.fruits.pop()
      }
    },
    deep: true
  }
}
  1. Utilize the formatter function of the component for validation purposes md-format and return null for entries longer than 30 characters

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

SyntaxError: VM3419:1 - Unexpected token "<" was not caught

I'm exploring AJAX techniques in a demo project where I retrieve data from the server using AJAX methods. However, I encountered the following error: " Uncaught SyntaxError: Unexpected token< xhr.onreadystatechange @main.js" JS: (function ...

I'm experiencing an issue with Bootstrap 5 where the code runs fine on codeply but not on my local machine

I'm attempting to replicate the scrollspy example found on the Bootstrap website. You can see my attempt here: . Feel free to inspect the code. While the navigation links function correctly, I've noticed that according to Bootstrap's docum ...

Techniques for transferring checkbox values to a JavaScript function

Here is the code snippet I am working with: <input type="checkbox" name="area" id="area" value="0">Some Text1</input> <input type="checkbox" name="area" id="area" value="80">Some Text2</input> Additionally, here is the JavaScript ...

Deleting occurrences of a specific text from a JSON document and subsequently analyzing its contents

I am having an issue with a JSON file in which there are strings of characters attached to many of the field names. This is making it difficult for me to target those objects in JS. The structure looks like this: "bk:ParentField": { "bk:Field": "Va ...

What is the process of integrating data retrieved from an SQL query into a Pug template using Express and MySQL?

Currently, I am in the process of developing a basic web application that will initially show a list of bus route numbers and names upon landing on the page. My tech stack includes MySQL integrated with Express and Pug. Below is the server-side code snippe ...

Dispatch prop within useEffect

App.js -> <Lobbies inGame={inGame} setLobby={setLobby} userName={userName} userKey={userKey}/> Lobbies.js -> import React, { useState, useEffect } from 'react'; import firebase from 'firebase'; const Lobby = ({userKey, ...

Assign a class to the element only when the second div also has a class

I am trying to create a functionality where I have a dropdown element (Li element) that receives an Active class when its parent div (button) is clicked. When the dropdown element has this class, I want to assign the same class to another div. If the dropd ...

Uncovering the characteristics of a GeoJSON data layer within Google Maps V3

Is there a way to access the properties of the data layer itself when loading a geoJSON file into a Google Map? I understand how to access the individual properties like posts_here, but I'm interested in obtaining the properties for the layer as a wh ...

What is the most effective method for broadcasting events to multiple component instances in Vue Js?

I am looking to implement the following behavior-> I have a list with simple elements (just text). Each element has an "edit" button, which opens up an edit form in the same place. There is also an "add" button at the top of the list, which opens the sa ...

Utilizing Jquery's each() method to retrieve the exact position of a specific class element

Is there a way to determine the position of the "owl-item active" element? The current position is 2 out of 3 total photos. <div style="transform: translate3d(-825px, 0px, 0px); transition: all 0.25s ease 0s; width: 48675px;" class="owl-stage"> ...

Steps to prevent uib-timepicker from automatically adjusting time based on the Browser Timezone

Currently in my database, timestamps are stored in UTC format. On the frontend, I am implementing uib-timepicker for time editing and updating purposes. However, I do not want uib-timepicker to automatically convert the time from the server's timezone ...

Struggling to retrieve cookie information within a Vue.js and Laravel project

As I develop an API for a Laravel 6 application located at example.com/api, alongside a Vue frontend situated at example.com, I encounter an issue with accessing the authentication cookie in my vue.js app. Despite successfully setting the cookie on user au ...

tips on utilizing the JSON information transmitted from the backend

$.ajax({ url: '{{ URL('reports/groupsUsersGet') }}', dataType: "json", data: { group_id : $('#group').val(), }, success: function(data) { <li>"i need to insert variable here"</li> }, error: function (data) ...

Is there a way for me to retrieve the data inputted into this form using JavaScript?

Having some trouble with this code. Can someone help me figure out what's going wrong? function displayData() { var userInput; userInput = document.getElementById(userInputs.firstInput); alert ("You entered: " + userInput); } <form ...

JavaScript regular expression for detecting valid characters without repeating a specific character

let rx = /(\/MxML\/[a-z0-9\[\]@/]*)/gi; let s = 'If (/MxML/trades[1]/value== 1 then /MxML/trades[type=2]/value must be /MxML/stream/pre/reference@href'; let m; let res = []; while ((m = rx.exec(s))) { res.push(m[1]); ...

Exploring Elasticsearch with Ajax Query Syntax

Attempting to send a post request via AJAX to my Elasticsearch index but encountering some issues. Here's the cURL result: [~]$ curl -XGET 'http://localhost:9200/firebase/_search?q=song:i%20am%20in' {"took":172,"timed_out":false,"_shards": ...

Understanding how to implement action logic in React Redux to control visibility of specific categories

Seeking guidance on how to implement action logic for displaying and hiding elements based on user interaction. Currently, all categories and subcategories are shown at once, but I would like them to be displayed only when a user clicks on them. When a use ...

Discover the Primevue DataTable feature that enables dynamic column and column grouping functionality, with the added bonus of gridlines disappearing as you scroll down

I am currently utilizing the PrimeVue DataTable feature with dynamic column and column grouping. Initially, when the table loads, everything appears to be great - gridlines are visible, columns freeze, scrollable functionality is working as expected. htt ...

Incorporating an Angular 2 Directive within the body tag of an

My goal is to create a custom directive that can dynamically add or remove a class from the body element in HTML. The directive needs to be controlled by a service, as I want to manage the visibility of the class from various components. Question: How ca ...

Utilizing Vue's shorthand syntax for interpolation within attributes allows for a more concise and efficient

I'm struggling with compiling a .Vue file in my Vue.js and Laravel SPA. Currently, I am attempting to add the following code snippet to my Home.vue: <ais-index app-id="{{ config('scout.algolia.id') }}" api-key="{{ env('ALGOLIA_SEAR ...