Is there a way to incorporate multiple rules from data into a text component using Vuetify?

I'm looking to establish specific rules within a mixin for my components.

Allow me to provide a straightforward example of my request:

Example Link

The code snippet:

<v-text-field :rules="[nbRules, requiredRules]" outlined v-model="name" label="Ticket Name" required></v-text-field>

...

requiredRules: [
  v => !!v || 'This field is mandatory',
],
nbRules: [
  v => v.length <= 10 || 'Name must be less than 10 characters',
],

However, as per the documentation

This feature accepts an array of functions that take an input value and either return true / false or a string containing an error message

, I attempted to pass an array but encountered the following error:

Rules should return a string or boolean, received 'object' instead

I also experimented with using computed properties like :

customRules(nb = 10) {
    const rules = [];

    if (nb) {
        const rule =
            v => (v || '').length <= nb ||
                `A maximum of ${nb} characters is allowed`

        rules.push(rule)
    }
    return rules
},

Yet, the same error persisted

Is there a solution to achieving my desired outcome?

Thank you

Answer №1

Currently, the issue lies in passing an array containing 2 other arrays into the rules property when Vuetify actually expects an array of functions.

To resolve this, you should merge the two arrays first. The most straightforward method to achieve this is by utilizing the spread syntax:

<v-text-field :rules="[...nbRules, ...requiredRules]" outlined v-model="name" label="Ticket Name" required></v-text-field>

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

Issue with jQuery selector not updating when variable changes

'I am attempting to create a functionality where a function is triggered upon clicking the "hit" class, but only when the correct parent "box" id is selected. var currentSelection = 1; $('#box-' + currentSelection + ' .hit'). ...

Setting up scheduled MongoDB collection cleanup tasks within a Meteor application

After developing an app to streamline form submissions for my team, I encountered a problem during testing. Meteor would refresh the page randomly, causing loss of data entered in forms. To solve this, I devised a two-way data binding method by creating a ...

How can I retrieve an image from a library and automatically update the image in SharePoint every 30 seconds?

I have a web part and I have written the code below: However, it is only fetching one image. How can I fetch all images from the library and change the image every 30 seconds using JavaScript or jQuery? public class MSDN : System.Web.UI.WebControls.WebPa ...

Stepping up Your Next.js Game with the Razorpay Payment Button Integration

When using the Razorpay payment button on a website, it provides a code snippet like this: <form> <script src = "https://cdn.razorpay.com/static/widget/payment-button.js" data-payment_button_id = "pl_FNmjTJSGXBYIfp" data ...

The variable remains unchanged even after the Vuex mutation has been executed

Currently, I am in the process of creating a settings page that involves fetching data from an API and utilizing Vuex for managing mutations. While the Vuex operations are completing successfully, it appears that the value of my dailyCount variable is not ...

Using jQuery UI Tabs to Dynamically Select a Tab Based on a Link

Recently, I have been exploring the idea of using a script to open a specific tab: $('.tofour').click(function() { // bind click event to link $tabs.tabs('select', 3); // switch to third tab return false; }); However, my dilem ...

Explain the inner workings of the setTimeout() function in JavaScript

My goal is to create a line in my code by placing points according to the line equation and adding a 100 millisecond delay before each point is displayed. However, when I try to run the code, it seems to wait for some time and then displays all the points ...

What is the best way to vertically center a button against a video using CSS?

How can I vertically center a button against a video using CSS? Here is my code: https://jsbin.com/curefoyefe/edit?html,css,js,output <video controls="" ng-show="myForm_live_video.live_video.$valid" ngf-src="live_video" width="200" height="200" class= ...

Modal form Validation errors remain present upon reopening

Problem Description In my project using Laravel 5.6.7 and Vue.js, I encountered an issue with a modal div that opens and closes on button click. After typing something in the form inside the modal, validation is triggered. If I close the modal and then re ...

Is Vue.JS compatible with AJAX requests for http calls?

I am currently attempting to achieve the following in my HTML: var app = new Vue({ el: '#loginContent', data: { main_message: 'Welcome', isAuthenticated: false, loginErrorMessage: '', ...

What steps should I take to set up nuxt 3 in such a way that it functions properly when I attempt to directly access a static page created through the command

Everything is functioning properly in my project when I execute npm run generate followed by npx serve .output/public. However, if I open the index.html file located in .output/public directory directly through my file system, only the initial display appe ...

Node development does not operate continuously

I'm facing a minor issue with node-dev. I followed the instructions in the readme file and successfully installed it. However, when I run the command like so: node-dev somescript.js, it only runs once as if I used regular node without -dev. It doesn&a ...

What steps can I take to generate 12 random div elements using jQuery out of a pool of 30?

Currently, all the words are displaying, but I would like the script to randomly select 12 out of the 30 words var randomdivs = $("wordstyle").get().sort(function(){ return Math.round(Math.random())-0.5; }).slice(0,12) $(randomdivs).show(); The follo ...

"Encountering a problem when trying to display Swagger-Editor for the second

While integrating the swagger-editor package into my React application, I encountered an issue. The first time I fetch the Swagger specifications from GitHub, everything works perfectly and validates correctly. However, upon rendering it a second time, an ...

jQuery AJAX call failing to return to page

Currently, my form is set up to upload multiple text fields and a file to a PHP script for saving. The script successfully saves the file and text fields to an SQL database. At the end of the PHP script, I have the following code snippet: ('state&apo ...

Error in React-Native: Unable to locate main project file during the build process

Just integrated cocoapods into a React Native project. After a successful build, RN is throwing this error... https://i.stack.imgur.com/czn2W.png No errors in Xcode during the build process, but Xcode is displaying these warnings https://i.stack.imgur.c ...

Eliminate nested object properties using an attribute in JavaScript

I am working with a nested object structured like this const data = [ { id: '1', description: 'desc 1', data : [ { id: '5', description: 'desc', number :1 }, { id: '4', description: 'descip& ...

Explore the possibilities with Intel XDK's customizable keyboard feature

I recently started using Intel XDK for development and I encountered the following issue: I have an input text field (HTML) and I need to restrict user input to only numbers, decimals, and negative sign when they click on the field. How can I achieve this ...

AngularJS: Issue with JQuery Slider not Updating Scope Value

I am currently working on a project using AngularJS and I have integrated a jQuery slider into it. However, I am facing an issue where I need to change the value of a select box which is defined in a $scope array, but the functionality is not working as ex ...

Retrieving the output of an asynchronous function within another function in JavaScript

I'm facing an issue with the Chrome API functions being asynchronous, making it difficult for me to get their return value. Here's a snippet of code that demonstrates my problem. I'm working with AngularJS. $scope.storageGet = function( ...