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: https://i.sstatic.net/CfvUH.png

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's Going on with My Angular Dropdown Menu?

Snippet of HTML code: <li class="nav-item dropdown pe-3"> <a class="nav-link nav-profile d-flex align-items-center pe-0" (click)="toggleProfileMenu()"> <img src="assets/img/profile-img.jpg" alt=& ...

Hitting a button causes Ajax.load to malfunction

Struggling to make ajax.load method work when clicking a button. The concept is simple: swap out the content of a div with something else using ajax.load. However, despite hours of research, I have yet to find a solution. Pressing the button does nothing. ...

`vuejs does not automatically scroll to the top of a div when a form error occurs`

Having 2 components with forms on the same page using Vue.js version 2.6. The second form emits a property when its submit button is clicked, which is then received and acted upon by the first form. The form also makes an ajax request for validation purpo ...

PHP for creating dynamic website search capabilities

As a beginner, I am working on developing an agriculture application to enhance my skills and take on a more advanced project. However, I am facing difficulties in implementing search functionality within the application. Here's what I have: - 4 sele ...

Retrieving subscriber count from Feedburner using jQuery and JSON

Is there a way to showcase the total number of feedburner subscribers in a standard HTML/jQuery environment without using PHP? The code snippet should be functional within a typical HTML/jQuery page. Perhaps something along these lines: $(document). ...

What is the process for manually looping an HTML5 video on iOS 4.3/5?

I'm facing an issue with a video that has specific segments I need to be looped. The problem arises on iOS 5, where after updating videoElem.currentTime for the third time, mobile Safari stops recognizing this attribute correctly. Interestingly, on i ...

Enhance your web form with the Bootstrap 4 tags input feature that allows users to add tags exclusively

I'm currently utilizing Bootstrap 4 along with Bootstrap Tags Input to create a multiple category selection feature. My goal is to enable users to choose multiple items exclusively from the predefined categories listed in the predefined_list. At pres ...

Mastering the art of gracefully transitioning to a fallback option when CSS grid

When it comes to creating a simple grid of squares (3x3 at most, filling in top to bottom left to right), I have encountered challenges with both flexbox and grid. The DOM structure required for each method seems incompatible or too complex to support both ...

Error: Attempting to access property 'question' of an undefined value

Trying to render information from a local .json file using Javascript functions, I encountered an error in the console for const answer despite being defined. I temporarily commented it out to test the function, only to receive the same TypeError for quest ...

Using various span elements with distinct alignment within an h1 tag in Bootstrap 5

How can I nest three span tags inside an h1 tag, aligning them differently? The first on the left, the second in the center, and the third on the right. Can this be achieved using Bootstrap or does it require custom CSS? ...

Moving files by dragging and dropping rather than deleting them

I have successfully implemented a feature using JavaScript to drag and drop multiple files, followed by displaying those images. The code below is fully functional without any errors. Need help with: I am now looking to add the ability to remove these ima ...

Responsiveness of the element along the vertical axis

I have an element that, when clicked, should display additional content. However, when the headline contains a lot of text, the element does not expand vertically as it should. Thank you for your help! Check out how it looks currently This is my HTML co ...

Using PHP as a data source, implement a feature in Google Maps that

I am currently working on incorporating an array of markers that are generated in PHP to a Google map. Below is the JavaScript code for my map: var map; var markers = []; var mapOptions = { //center: new google.maps.LatLng(locations[0].lat, locations[0 ...

Executing a function after a subscriber has finished in Angular 8+

Welcome fellow learners! Currently, I am diving into the world of Angular and Firebase. I am facing an interesting challenge where I fetch ticket data from my collection and need to add new properties to it. However, the issue arises when my ordering funct ...

JavaScript ES6 array method for generating an object from an array

I wish to transform the following array: [ { event: "LIB", block_calendar: "YES", obs: "Lorem Ipsum", status: "Block", }, { event: "LIB" block_calendar: "YES" o ...

Having multiple instances of jQuery running concurrently on a single webpage

I am a novice when it comes to jQuery and I'm facing some issues with it. I have a basic slideshow and a weather plugin that I would like to incorporate, but strangely they both seem to malfunction when used together. <script src="js/jquery.js"> ...

Javascript program that generates drag and drop elements using HTML5 features:

Whenever I attempt to drag and drop elements that are normally created by HTML, everything works fine. However, when I try to drag and drop elements generated by JavaScript, I encounter the following error: Uncaught TypeError: Cannot read property 'p ...

Harnessing Spread Syntax with Map and Filter Operations

Recently stumbled upon a fascinating problem that I couldn't wait to share with all of you. Here is the question at hand: [...[0,1,...[-1,0,1].map((x)=> x+1)].filter((x)=>x)),7] I managed to successfully solve the initial section up to the fi ...

Is it normal for Node's console to not display all object properties?

After running some code, I noticed something peculiar. console.log(myURL); It seems that the extension property is missing: console.log(myURL.extension); However, when logging it on its own, the value appears correctly. The URL object was created ...

Avoiding duplicate touch events with an if statement

I am currently working on a module for a responsive website that involves tapping the initial screen to reveal a panel from the right. The user can then tap a close button to hide the panel. However, there is an issue where if the user taps multiple times ...