When employing autoForm in Bootstrap 4, where is the "form-control" class established?

Currently, I am working on developing a personalized autocomplete type feature for the afQuickfield in my Meteor project. The main issue I am facing is that when I specify the type="autocomplete" on the afQuickfield, the class="form-control" attribute seems to be missing. Interestingly, it is present for all other field types.

In my attempt to resolve this issue, I searched for the term form-control throughout the entire codebases for both the meteor-autoform and the scss as well as js directories of the bootstrap library. The results only showed occurrences in the changelog and in class definitions within the scss/css files.

One possible solution could be simply adding class="form-control" to the afQuickfield definition. However, I am hesitant to resort to such a quick-fix approach.

I am seeking assistance in understanding how the form-control attribute is assigned in autoForm fields. Any insights would be greatly appreciated.

Below is a snippet of my custom autocomplete code (still a work in progress). I am starting with a basic text element with the appropriate atts and plan to build upon it:

// autocomplete.js
AutoForm.addInputType('autocomplete', {
  template: 'afAutocomplete',
  valueOut: function () {
    return this.val()
  },
  valueConverters: {
    stringArray: AutoForm.valueConverters.stringToStringArray,
    number: AutoForm.valueConverters.stringToNumber,
    numberArray: AutoForm.valueConverters.stringToNumberArray,
    boolean: AutoForm.valueConverters.stringToBoolean,
    booleanArray: AutoForm.valueConverters.stringToBooleanArray,
    date: AutoForm.valueConverters.stringToDate,
    dateArray: AutoForm.valueConverters.stringToDateArray
  },
  contextAdjust: function (context) {
    context.atts.autocomplete = 'off'
    return context
  }
})

// autocomplete.html
<template name="afAutocomplete">
  <input type="text" value="{{this.value}}" {{this.atts}} />
</template>

For comparison purposes, here is the code snippet from the type="text" field:

// text.js
AutoForm.addInputType('text', {
  template: 'afInputText',
  valueOut: function () {
    return this.val()
  },
  valueConverters: {
    stringArray: AutoForm.valueConverters.stringToStringArray,
    number: AutoForm.valueConverters.stringToNumber,
    numberArray: AutoForm.valueConverters.stringToNumberArray,
    boolean: AutoForm.valueConverters.stringToBoolean,
    booleanArray: AutoForm.valueConverters.stringToBooleanArray,
    date: AutoForm.valueConverters.stringToDate,
    dateArray: AutoForm.valueConverters.stringToDateArray
  },
  contextAdjust: function (context) {
    if (typeof context.atts.maxlength === 'undefined' && typeof context.max === 'number') {
      context.atts.maxlength = context.max
    }
    return context
  }
})

// text.html
<template name="afInputText">
  <input type="text" value="{{this.value}}" {{this.atts}}/>
</template>

It is evident that these two are quite similar, yet the autocomplete version lacks the form-control class in the actual HTML output.

If you have any suggestions or solutions, please feel free to share them. Thank you!

Answer №1

It appears that there is an issue stemming from AutoForm, as it should be throwing an error indicating multiple templates named 'afInputText' when afInputText is included:

There are multiple templates named 'afInputText'. Each template needs a unique name

What about the missing form-control class?

The absence of a class attribute on the input within the afAutoComplete template is indeed correct.

AutoForm's built-in input types do not include class attributes, as they are designed to be modified by themes.

For instance, the text input in the Bootstrap 4 theme currently appears as follows:

<template name="afInputText_bootstrap4">
  <input type="text" value="{{this.value}}" {{attsPlusFormControlClass}}/>
</template>

This is itself defined as a helper.

How should one safely define the template?

To future-proof your component and logic for a potential transition from Bootstrap 4 to Bootstrap 5, you can follow the previously outlined steps:

// autocomplete.js
AutoForm.addInputType('autocomplete', {
  template: 'afAutocomplete',
  valueOut: function () {
    return this.val()
  },
  valueConverters: {
    stringArray: AutoForm.valueConverters.stringToStringArray,
    number: AutoForm.valueConverters.stringToNumber,
    numberArray: AutoForm.valueConverters.stringToNumberArray,
    boolean: AutoForm.valueConverters.stringToBoolean,
    booleanArray: AutoForm.valueConverters.stringToBooleanArray,
    date: AutoForm.valueConverters.stringToDate,
    dateArray: AutoForm.valueConverters.stringToDateArray
  },
  contextAdjust: function (context) {
    context.atts.autocomplete = 'off'
    return context
  }
})
// autocomplete.html
<template name="afAutocomplete">
  <input type="text" value="{{this.value}}" {{this.atts}} />
</template>

Additionally, create a separate template to override the styling:

<template name="afAutocomplete_bootstrap4">
    <input type="text" class="form-control" value="{{this.value}}" {{attsPlusFormControlClass}} />
</template>

The key here is the combination of afAutocomplete and _bootstrap4, which AutoForm uses to determine the current template based on the default theme or the theme utilized by the current form.

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

Is there a way to enable text selection on a jQuery draggable div?

I utilized jQuery to make a specific div draggable, but I've encountered an issue. Inside this draggable box, there is some important text that I need to be able to copy and paste. However, whenever I click on the box, it triggers the dragging action ...

Using React Hooks to render radio buttons within a map iteration

My code contains a nested map function where I try to retrieve values from radio buttons. However, the issue is that it selects all radio buttons in a row instead of just one. Below is the snippet of my code: <TableHead> <TableRow> ...

Invoke the loaded function using ajax

I am populating my div with data from an HTML file using the following code: $('#result').load('ajax/test.html'); Within test.html, there is a function called alertme. Is there a way to execute this function after the HTML is loaded i ...

How to Retrieve the Following Element in a Table Using Javascript

https://jsfiddle.net/en6jh7pa/1/ I am encountering an issue with accessing the next element, as it is returning null. When I pass "this" as the onclick parameter, I expect to be able to grab the next element using this keyword. However, it seems to be re ...

Differentiating the texture of a pointCloud in three.js shaderMaterial: A step-by-step guide

Utilizing THREE.PointCloud for optimum performance, I aim to animate 100,000 objects. However, I am facing an issue with setting different textures for particles. How can I incorporate uniforms with various textures in this code? Is it possible to pass s ...

Is there a way for me to verify if I have already made an AJAX data request

I have an image gallery with thumbnails. When a user clicks on a thumbnail, an ajax request is fired. I want to prevent the ajax request from firing again if the user clicks on the same thumbnail and instead use the existing data. $.getJSON(url, function( ...

Keep retrying a request until a valid response is received

I am working with an API that requests data from a backend service. Sometimes, the data may not be available at the time of the initial request. In such cases, I need the system to retry up to 5 times until the data is present. I can confirm that the dat ...

I'm intrigued: what type of syntax is Facebook's polling service utilizing in the callback?

While monitoring the Network Monitor on Chrome's developer tool, I observed how Facebook updates content on their news feed. All AJAX responses start with the following: for (;;);{"__ar":1,"payload":[]} I'm curious about what the for(;;); piec ...

Issue found: React-Redux action is not being dispatched

I'm currently working on setting up Google authentication in my React Next.js application. The process involves sending the access token to my backend, where it is validated before a new token is returned in the header for accessing protected resource ...

Issue with Bootstrap error class not functioning in conjunction with hide class

I need to create a form that slides down two input fields when an error occurs, and I want them to have the bootstrap error class. The 'error' class works fine without the 'hide' class being present, but when the 'hide' class ...

Utilize JavaScript to seamlessly play a Spotify track within the Spotify client without disrupting your current

A little while back, I recall the simplicity of clicking play on a song within a website and having it instantly start playing on my computer without any additional steps. It was seamless and effortless. My goal for my website is to have music start playi ...

Transition the background image color smoothly from left to right in a seamless and continuous movement

A switch button located in the top right corner can toggle between light and dark modes. The background features a zoomed-in image. Currently, the transition is as follows: From left to right when switched to dark mode From right to left when switched to ...

Configuring hostname and port within next.config.js with next.js

Currently, I am utilizing next.js 9.5.x and am in search of a method to set up the hostname and port via the next.config.js file. Despite consulting the documentation, I have yet to discover a solution to this issue. Previously, I leveraged a series of .e ...

managing arrays in JavaScript with multiple tables

**I have successfully written code for calculating the sum of inputs in one table** $('#example122').on('input', '.calculate', function () { calculateTotal(); }); function calculateTotal() { var grandTotal = 0; $ ...

Incorporate Error Text Spacing in Input Group Design

I'm currently working on developing a method to incorporate space for error messages within my form input group component. The main objective is to prevent any displacement of elements on my forms when displaying error messages. In this scenario, it ...

Connect various inputs in Vue.js so they can be updated simultaneously

I need to have multiple text inputs that are interconnected, so when I change the value of one input, the others should update with the same value. These inputs are being generated dynamically in a loop using v-for as shown below: <tbody> <varia ...

Confirmation Dialog with FancyBox for Deletion

Looking to add a delete confirmation dialog using FancyBox. The idea is to provide the url to FancyBox and then proceed to the defined url to perform the delete action when the user clicks on the "Yes/Confirm" button. Has anyone tried this before and hav ...

Setting cookies in Express will not work if you are using res.sendFile()

After implementing the res.sendFile() function, I noticed that the set-cookie header is not being received in the response. app.get(sessionTracker, (req, res, next) => { res.cookie('tracker', '123a', { maxAge: 172800000, h ...

Retrieve the CSS class definition using the console in the Chrome Developer Tools

Is there a way to automatedly extract CSS class definitions from Chrome Developer Tools? I want to retrieve the styles defined in a specific class name, similar to how it is displayed in the Styles tab on the right-hand side. I know about the getComputedS ...

Display the size of the data array in VueJS once the data has been retrieved from the API

Using Vue JS, I have been attempting to retrieve data from an API. My goal is to determine the length of the array and then log it to the console using a method. However, every time I try to do this, the value logged is always "0" instead of the actual le ...