Vue.js - The @oninput.native listener does not trigger in b-form-textarea components

I have a Vue application and I am trying to incorporate Facebook inspired buttons inline in a comment form. Previously, I had a plain JavaScript prototype that was functional. However, when integrating it into my Vue app, I encountered issues due to multiple occurrences of the component on the page caused by heavy use of element IDs. While attempting to declare dynamic IDs, I realized it did not work well because <style> is static. After some research, I came across the concept of using refs which was highlighted in this helpful article: https://www.telerik.com/blogs/how-to-target-the-dom-in-vue. To summarize, despite implementing this solution, my callback function is still not being called.

View CodeSandbox Demo

Here is a snippet of the source code:

<b-form-textarea
  class="textarea" ref="textareaRef"
  rows="1" max-rows="8"
  @oninput.native = "adjustIconsInTextarea"
  :placeholder="$t('comment.write-comment-placeholder')"
  v-model="text"
>

<div class="icons" ref="iconsRef">
  <b-button :id="`emoji_list_${commentId}`" class="mt-2" variant="outline" size="sm">
    &#x1F600;
  </b-button>
</div>

methods: {
adjustIconsInTextarea() {
  const textComment = this.$refs.textareaRef;
  console.log(textComment.value.length);
  const icons = this.$refs.iconsRef;
  if (textComment.value.length > 140) {
    textComment.style.padding = '13px 50px 34px 32px';
    icons.style.top = '-36px';
    icons.style.right = '72px';
  } else {
    textComment.style.padding = '10px 174px 5px 28px';
    icons.style.top = '-45px';
    icons.style.right = '68px';
  }
},

Referencing Bootstrap-Vue's b-form-textarea events. Can you spot the error?

Answer №1

As stated in the documentation:

All standard events (excluding the custom input and change events) are fully supported, no need for the .native modifier.

Therefore, you should use the following syntax:

@input= "adjustIconsInTextarea"

Also, make sure to utilize the event parameter instead of

refs</pl> when referencing the textarea element in your method:</p>
<pre><code>methods: {
adjustIconsInTextarea(event) {
  const textArea = event.target;
  console.log(textArea.value.length);
  const icons = this.$refs.iconsRef;
  if (textArea.value.length > 140) {
    textArea.style.padding = '13px 50px 34px 32px';
    icons.style.top = '-36px';
    icons.style.right = '72px';
  } else {
    textArea.style.padding = '10px 174px 5px 28px';
    icons.style.top = '-45px';
    icons.style.right = '68px';
  }
},

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

Send an ArrayList to jQuery Flot

Good day. Apologies for any language barriers as English is not my first language. I am a novice in [see tags] and I have a web application that gathers a date and a serial number to execute a SQL query. The query returns some data (measurement values an ...

Show the message "No results found" if there are no matches, or hide the DIV displaying search results using AJAX and MySQL

I'm struggling with getting my search bar to display "No matches found" or hide the results div completely when a query doesn’t match any “Name” in the MySQL database. The search bar works for displaying AJAX live search results using MySQL, PHP ...

When trying to execute npm run build, an error is encountered stating: Unable to locate 'Vue'

After executing npm run build or npm run dev, an error message is generated as follows: ERROR in ./src/components/screens/login/login.js?vue&type=script&lang=js& (./node_modules/babel-loader/lib!./node_modules/eslint ...

Creative ways to use images as borders with CSS in React JS

import React, { Component } from 'react'; class BigText extends Component { constructor(props) { super(props); this.state = { title: '', text: '', summary: '' ...

After consolidating buffer geometries, adjusting the transparency/opacity of the shapes is not an option for me

I've been working on a model with multiple boxes and trying to optimize draw calls by using buffer geometry merger. However, I'm facing an issue where I can't change the opacity of geometries after merging. Here are the things I've tri ...

Can you provide me with a variable that will give me the total size of the scrollbar?

How can I determine the maximum number of pixels scrolled on a webpage? I attempted using window.pageXOffset, but it only gives the current scrolled amount. I require the total size at all times. ...

Is there a way for me to move the dot icon along the dotline?

Here is the code snippet: jsFiddle I have successfully implemented a click event to change the style of selected dots in dotline. Now, my query is : How can I enable dragging functionality for the dot icon within dotline? Your assistance on this matte ...

Creating a conditional statement in jQuery that will append text to a specific DIV element after a form has been successfully

I currently have a form set up that is functioning properly, but I am looking to make some changes. Instead of redirecting the user to a new page with a success message upon submitting the form, I want the success message to be displayed in a div next to t ...

html.input javascript/jquery

This is an example of an AJAX form with 2 textboxes and a radio button to choose between unlocking and resetting the password. The goal is to make the password label and textbox disappear when the "Unlock" option is selected. However, this cannot be achi ...

Attempted to identify whether an item exists in an array, and if it does, then add the item to the array; if not, then perform

Allow me to make some clarifications as it might be a bit confusing initially. This project I'm working on is for school. I don't expect anyone to do it for me, but I need help with a specific part. I'm creating a simple shopping cart using ...

In TypeScript, the function is failing to retrieve the complete array value

I'm facing an issue with a program that is supposed to piece together all the letters, but it's not functioning correctly. I've tried using the debugger, but it doesn't display any errors. Here's the code snippet: var phrase = [ &a ...

Testing of onClick event in a React component using styled-components with Sinon spies

Utilizing sinon to test a react component and verify that an onClick function is triggered. Struggling to target the element to click on due to the use of styled-components. Encountering this error message: The "simulate" method should only be run on ...

Encountered an issue when attempting to access a file on the desktop using Node.js

Here is the code I am using to read a simple file from my desktop: module.exports = function (app) { app.get('/aa', function(req, res) { fs = require('fs'); fs.readFile('‪C:\\Users\\t5678 ...

With Ionic, you can use one single codebase for both iPad and iPhone

I currently have a complete app developed using ionic and angularjs that is functioning well on iPads and Android devices. Now we are looking to launch it for iPhones and Android smartphones with some design modifications. Is there a method to achieve th ...

I'm encountering an issue in my server.js file where I am unable to read the property 'collection' as it is undefined

I have encountered an error in my code: /home/ubuntu/workspace/server.js:43 db.collection('quotes').find().toArray(function(err, results) { ^ TypeError: Cannot read property 'collection' of undefined at Object.<anonymous> ( ...

What is the technique for performing asynchronous querying of multiple SQL databases?

Currently, I am in the process of developing a web application using nestjs and typeorm. I have been contemplating the functionality of the following code: const r1 = await this.connection.query(sqlA) const r2 = await this.connection query(sqlB) Does th ...

How can I customize the visibility toggles for the password input field in Angular Material?

Currently immersed in the Angular 15 migration process... Today, I encountered an issue with a password input that displays two eyes the first time something is entered in the field. The HTML code for this is as follows: <mat-form-field appearance=&qu ...

Enabling HTML and Markdown in the footer of VuePress

I am currently attempting to incorporate HTML/markdown into the footer variable within VuePress' default theme. My goal is to include a URL in the footer that directs visitors to my website. Unfortunately, I have been unable to find a straightforward ...

Updating dynamic content in IBM Worklight V6.1 with jQuery Mobile v1.4.3 requires waiting for the DOM to load

I need to dynamically update the content of a div within my HTML page structure. <!DOCTYPE HTML> <html> ... <body> <div data-role="page"> <div data-role="header"> //Image </div> <!-- Th ...

Is it Unwise to Depend on Props within the useReducer Hook?

Within my App() component, I utilize props named data. This particular component relies on a useReducer hook to manage its state. The reducer function is responsible for determining when to display or hide specific data based on the state. Additionally, it ...