Using multiple widgets for a single form field in a Django application

Below is the form structure I am working with:

    class ExcipientForm(ModelForm):
    class Meta:
        model = Excipient
        fields = (
            "Excipient_type",
            "Excipient_concentration",
        )
        widgets = {
            'Excipient_type': Select(attrs={
                'style' : 'width:100%;',
                'class' : 'dropdowns',
                }),
            
            'Excipient_concentration': TextInput(attrs={
                'class': 'slider',
                'type': 'number',
                'value':"20", 
                'max':"100", 
                'step': "0.1",
                'id':"excipient_concentration"
                }
            )
        }

ExcipientFormSet = inlineformset_factory(
    Parameters,
    Excipient,
    ExcipientForm,
    can_delete=False,
    min_num=1, 
    extra=0
)

Here is how the template should look like to post to the form:

<form action="" id="form-container" method="POST"> {% csrf_token %} <div class='row'>
     <div class='col'>
       <label for="id_API_batch_number" class="form-label">API batch number : </label>
     </div>
     <div class='col'>
       {{ parameter_form.API_batch_number }}
     </div>
   </div>
   <hr class="my-4">
   <div class='excipient-form'>
     {{ excipient_form }}

     {{excipient_form.id.auto_id}}
     <input type="range" class="slider" name="slidervalue" value='20' max="100" step="0.1" onchange="updateTextInputRange(this.value);">
   </div>
   <button id="add-form" type="button">Add Excipient</button>
   <hr class="my-4">
   <label for="num6" class="form-label">Total Concentration: </label>
   {{ parameter_form.Total_concentration }}
   <br></br>
   <input type="submit" id="submit" class="btn btn-primary" value="Submit">
 </form>

I am attempting to synchronize the sliders and their corresponding number fields.

https://i.sstatic.net/sW2pu.png

As of now, this is the JavaScript function I have:

//Update Textbox value from slider value
  function updateTextInputRange(val) {


    document.getElementByID('excipient_concentration').value = val;  // text input
    //checkValueSum();
  }

Here are some approaches I have tried:

  1. Identifying the ID for each instance of the slider and number input, but all instances share the same ID.
  2. Using multiple widgets in the same form, which resulted in the html element taking on the properties of the final widget.
  3. Adding another field in the model and using it as a slider in the forms widget, but this does not allow me to synchronize the slider and number values without making a server call.

Any suggestions on how to achieve this synchronization?

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

I am in need of a blank selection option using an md-select element, and I specifically do not want it to be

I'm currently utilizing Angular Material with md-select and I am in need of creating a blank option that, when selected, results in no value being displayed in the select dropdown. If this blank option is set as required, I would like it to return fal ...

Can text or images be easily moved by dragging and dropping on a canvas?

Exploring different HTML5 canvas demo, I find myself questioning how to incorporate drag and drop functionality for text, images, or shapes like rectangles. Can you suggest a way to add drag and drop capability to the canvas? ...

Using Nuxt.js: Incorporating Components into Your Layout

Recently, I decided to dive into Nuxt.js and experiment with its capabilities. One idea I had was to customize the default layout by adding a header and footer to it. To achieve this, I planned on creating separate Header and Footer components and enclosin ...

Using the overflow-y property with a value of auto will hide any content that

I'm attempting to create a scrollable container for cards where the scrolling is restricted to the card content only, excluding the header and footer. My assumption is that the container should hide horizontal overflow and each card should have overfl ...

Exploring the implementation of multiple websocket connections with Django Channels

After happily using Django-Channels for a few months, I decided to add a second websocket dependent application to my Django project. However, I encountered some trouble along the way. The error message that keeps popping up is "websocket connection faile ...

Create a custom sorting option for an Angular select dropdown menu that is tailored to a specific

<select name="region" id="region" ng-options="id as name for (id, name) in regions[entry.country]" ng-model="entry.region" class="form-control select-styled" required></select> I am looking to implement a filter or custom sort to rearrange th ...

Utilizing nested LESS statements for styling the :before and :after pseudo-classes

Here is a snippet of LESS code attempting to add a colored background to the :after pseudo-class: .hexagon:after { content: ""; position: absolute; bottom: -50px; left: 0; width: 0; height: 0; border-left: 100px solid transparent; border-r ...

Adjust the Width on the X Axis with Three.js

I am currently working with an object in Three.js, which has been exported in JSON format for easier use. I am looking to adjust the width between the X axis of the object without using the scale function, as it affects the angles of the object in ways tha ...

Styling the background image links in a responsive navbar in CSS to be responsive and scale appropriately

Currently, I am working on a parallax WordPress site for a client where I have implemented a navbar with a sprite as the background image for each link. You can view the seven-link navbar on this page (). The navbar looks great on desktop screens, but I am ...

The state in Reactjs is not displaying as expected

Check out my ReactJS todo app that I created. However, I am facing an issue with deleting todos. Currently, it always deletes the last todo item instead of the one I click on. For example, when trying to remove 'Buy socks', it actually deletes ...

Guide on how to transform form data into an object containing nested properties

Considering the inputs provided below: <input name="person[1]['first']" /> <input name="person[2]['first']" /> <input name="person[3]['first']" /> The objective is to convert this into an object structure a ...

Postpone an automatic action in React

I'm currently working on adding a fade out animation to a page change in React, but I need to delay the click event before the page actually transitions. Here's the code snippet I have so far: export default function Modal({setTopOf}) { const ...

Ajaxed div disappears and reappears only after the div has finished loading

I ran into an issue with my jquery ajaxed site. The main content div is in the center with navigation on top. I needed to AJAX the content to prevent the flash video from restarting after each page load. My solution involved using the following code: $(do ...

Two headings using the same tags appear distinctively rendered

Recently, we added an iframe to our company's website that I have been helping manage. This iframe is responsible for handling requests sent to our organization. Interestingly, the headings on our website are styled using the following CSS: color: # ...

Step-by-step guide on building a route map using ngRoute in AngularJS

I am in the process of developing a web application similar to gdrive or dropbox. As I navigate through my folders via links, I require the path to be displayed in the URL. I want to update the path from the client side using AngularJS. For example: $st ...

Getting filenames from a directory using PHP

I'm attempting to retrieve the folder name from my computer using PHP code. After researching on Stack Overflow, I came across the following information: <input type="file" name="folder" webkitdirectory directory multiple/> Directory Chooser i ...

Inconsistent Functionality of Bootstrap Popover

I am experiencing an issue with the bootstrap Popover feature. It seems to work inconsistently - sometimes it works and other times it doesn't. I am using it to create a popover that displays a user's information when a visitor hovers over the us ...

Is there a way to trigger element closure using the esc key?

I have a panel that shows on initialization and hides when I press the 'close' icon. How can I make the panel close when I press the 'esc' button? Below is the HTML code for the panel: <div ng-init="vm.onInit()" class="mainContent"& ...

Why does calling $resource (or $http) from inside a callback in Cordova and AngularJS result in a 404 error?

After successfully transitioning my functional angularjs web app to Cordova and compiling it for iOS, I encountered an issue while testing the app on iOS. When trying to access a local file from inside a callback response (after successfully accessing anot ...

Inserting items into an array entity

I am attempting to insert objects into an existing array only if a certain condition is met. Let me share the code snippet with you: RequestObj = [{ "parent1": { "ob1": value, "ob2": { "key1": value, "key2": va ...