Unable to decrease the width of a div element in Vuetify and Nuxt

As I work on creating a dynamic form with fields that need to occupy only 50% of the size of a regular field, I encounter different components based on data provided by Vuex.

The use of v-for in Vue.js helps me loop through form objects and render the appropriate component on screen - whether it's a TextField, DateField, CheckField, or any other defined type.

Let's dive into the code:

In store/module/forms.js (Vuex), you'll find an array of form objects, each specifying details like name, type, value, and options. The 'css' property within 'options' controls the width of the field, set at 50% here.

[
  {
    name: 'familiarIncome',
    type: 'TextField',
    value: '',
    options: {
      dataname: 'familiarIncome',
      mandatory: true,
      label: 'Renda familiar',
      placeholder: '',
      rules: fieldRules.float('a renda familiar'),
      css: 'width: 50%', // This style will be applied to the component
    },
  }
]

Next, in pages/formulario.js: (only three input components have been written so far)

<template>
  <v-app class="container d-flex justify-center">
    <h1>Coleta de dados</h1>
    <v-form class="container fluid">
      <h2>Dados pessoais</h2>
      <div class="personal-data d-flex flex-wrap">
        <div
          v-for="field in getForm.personalData"
          :key="field.name"
          class="field"
          <!-- This 'field' class is significant -->
        >
          <component
            :is="field.type"
            v-bind="field.options" 
            @change="updateData((section = 'personalData'), $event)"
          ></component>
        </div>
      </div>

      <div class="social-benefits"></div>
      <div class="is-disabled"></div>
      <div class="address"></div>
      <div class="child-already-born"></div>
    </v-form>
  </v-app>
</template>

<script>
import { mapGetters } from 'vuex'
import TextField from '../components/inputs/textfield.vue'
import ConfirmButton from '../components/inputs/confirmbutton.vue'
import SelectField from '../components/inputs/selectfield.vue'

export default {
  name: 'Formulario',
  components: { TextField, ConfirmButton, SelectField },
  data() {
    return {
      formToken: this.$route.params.token,
    }
  },
  computed: {
    ...mapGetters(['getForm']),
  },
  methods: {
    updateData(section, eventData) {
      const data = {
        section,
        ...eventData,
      }
      this.$store.commit('setFormField', data)
      console.log(this.$store.state)
    },
  },
}
</script>

<style scoped>
.field {
  padding: 7px;
  width: 50%;
}

h1 {
  font-size: 36px;
}

h2 {
  font-size: 24px;
}
</style>

Here's a snapshot of the webpage:

If there are any crucial details I've missed, feel free to point them out ;)

(Just clarifying, I did extensive research before reaching out for assistance.)

Answer №1

After a few minutes of experimenting and intentionally trying things that seemed incorrect (a surprisingly effective technique), I was able to solve the problem.

I ended up removing the enclosing div around the <component> tag, allowing the 50% width to work as intended.

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

What is the best way to integrate a CSS designed flag in my website's top navigation bar?

My goal is to make my website multilingual, allowing users to switch between languages using flags in a dropdown menu. Initially, I tried creating the flag images solely with CSS for better resizing ability but faced difficulties. So, I resorted to using s ...

What causes the absence of CSS classes in production while utilizing Tailwind and next.js?

Tailwind version: v9.3.5 PostCSS Configuration: // postcss.config.js module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, ...(process.env.NODE_ENV === 'production' ? { '@fullhuman/p ...

Instructions for implementing tooltips on a pie chart slice when hovering with the mouse pointer, using the canvas

var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); var cw = canvas.width; var ch = canvas.height; ctx.lineWidth = 2; ctx.font = '14px verdana'; var PI2 = Math.PI * 2; var myColor = ["Gr ...

Loss of styling is observed with jQuery's html() function

Here is the HTML code I am working with: <div class="myList"> <select> <option value="1">Item1</option> <option value="2">Item2</option> </select> </div> Everything looks great in terms of CS ...

There seems to be a column in the MySQL INSERT query that is unidentifiable and does not exist in the list of fields

id and cost are required as integers and cannot be left empty. I encountered the following error message: 'Error: ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'field list'' var sql = "INSERT INTO Paintings(` ...

Error encountered in React V16.7: The function is not valid and cannot be executed

import React, { useContext } from 'react'; The useContext function is returning undefined. Error Details: Uncaught (in promise) TypeError: Object(...) is not a function Error occurred when processing: const context = useContext(UserCon ...

Displaying Font Awesome icon within a loop in a Vue.js component

I am trying to display icons within a v-for loop. The data for the links and icons is stored in a JSON file. However, I am facing an issue when trying to use Font Awesome icons with Vue.js. When I include Font Awesome via CDN, everything works fine. But wh ...

Struggling with running a jQuery ajax request inside a function?

Below is my code for a jQuery Change Event: $("input[name=evnt_typ]").change(function(){ var request = $.ajax({ method: "POST", url: "ajaxRequest.php", dataType: "json ...

Searching for a specific element in jQuery by querying a string

I have a situation where an ajax request is made to send text using the POST method to another PHP page. This PHP page then converts the text into markdown format and sends it back. Here's an example of what it looks like: "<p>Meep, meep, <e ...

AJAX and Python conflict - The requested resource is missing the 'Access-Control-Allow-Origin' header

I am currently developing a unique JavaScript library that has the capability to communicate with a basic Python web server using AJAX. Below is the snippet for the web server class: class WebHandler(http.server.BaseHTTPRequestHandler): def parse_PO ...

The submission of the Jquery form is not successful

I am struggling with a form on my page. I want to disable the submit button and display a custom message when submitted, then use jQuery to actually submit the form. <form> <input type="text" name="run"/> <input type=&quo ...

JavaScript callbacks are not executed synchronously

My Objective : I am attempting to initiate a payment order in the payment gateway server and then send back the order details to the client using Firebase cloud functions. This process involves utilizing firebase cloud functions. The Order() function ha ...

Navigating a double entry validation in a Java script prompt while utilizing Selenium

Can someone please assist me with the following scenario: I need to complete a double entry check prompt/alert that contains two text boxes. The task is to fill in these two text boxes and then click on the OK button. Potential solutions attempted: I tr ...

Run some code and then enter interactive mode

Is there a method to run certain code (from a file or a string) before entering interactive mode in node.js? For instance, if I have script called __preamble__.js with the following content: console.log("preamble executed! poor guy!"); and a user enters ...

Table header containing the weekdays for a jQuery calendar display

I need some assistance in creating a basic monthly calendar using a table. Check out this demo: www.jsfiddle.net/pzdw0s2n/1/ ...

Tips for successfully passing an entire object in the data of a datatable column property

I am currently using Datatables version 1.10.21 and implementing ajax with the column property to generate the datatables successfully. ajax: { url: dataUrl, //using dataUrl variable dataSrc: 'data' }, co ...

When I submit my form in Django, the data does not get added to the database

My current project involves creating a contact page for a website using Django. The goal is for clients to enter their information, which should then be submitted to the database. Even though the form is submitting without errors and the project runs smoot ...

What is the best way to adjust a wide HTML table to make it narrow enough to fit perfectly within the screen width?

I need assistance with formatting an HTML table that contains multiple columns: <table id="req_header" border="2" style="overflow: auto;"> <tr> <th><i class="fa fa-solid fa-check"> ...

What causes the scrollTop to appear erratic?

There is a simple issue that I find difficult to explain in text, so I have created a video demonstration instead. Please watch the video at this link: The functionality on my page works perfectly when scrolling down, as it replaces images with the next i ...

Step-by-step guide on repairing a countdown clock using JavaScript, HTML, and

I'm having issues with my JS on my website. I am new to this and currently in the process of setting up a website. I want to add a timer to show when the site will be active. It seems like there is an error somewhere in the JS code that I can't ...