Customize DAT.GUI: adjust the width of the text field to accommodate longer text entries

Is there a way to increase the width of a text field using DAT.GUI library in JavaScript?

According to this source, you can achieve it by setting the style attribute for the first controller like this:

gui.add(params, 'StartingVector').name('Starting Vector : ');
gui.__controllers[0].domElement.style = "width:100%";

However, even with this modification, it seems that adding long text to the field is still an issue. Here's an image showing the field without the style modification:

On the contrary, here is an image with the modified style and a long text added to the field:

gui.add(params, 'StartingVector').name('Starting Vector with testing a long text like this : ');

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

As shown, it appears that the long text is truncated even after applying the style change.

If you have any suggestions on how to widen the text field to accommodate longer text, please let me know.

Please note that the dat.gui.js file I'm using can be found at [dat.gui.js][4]

Update 1

@

After implementing your suggested solution to customize the appearance of the text field, I encountered an issue where the bottom right case hides part of the long text ""A Single long line just for some fun"", displaying only ""A single lin" instead. How can I get rid of this grey case on the right?

This is what I tried in my JS script based on your advice (assuming '4' refers to the fourth row in my menu):

gui.__ul.childNodes[4].classList += ' longtext';
gui.__ul.childNodes[4].childNodes[0].childNodes[0].classList += ' full_width'; 

Here are the corresponding CSS styles:

.longtext {
           line-height: 13px !important;
           height: 40px !important;
          }
    
.full_width {
             width: 100% !important;
            }

Update 2

The script I'm working on can be accessed via [this link][6]. The issue lies between lines 272 and 307, specifically within the 'StartingVector' section of the 'params' structure:

 // Relevant code snippet from the script
 272 var params = {
 ...
 291 gui.add(params, 'StartingVector').name('Starting Vector with testing a long text like this : ');
 ...
 

Despite following your instructions, the text gets cut off after the word "with," failing to display the entire phrase. Even after applying the CSS styles you provided, the problem persists.

To illustrate the issue further, here's a screenshot:

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

I am looking for a way to set the text fixed and prevent it from being edited by the user, similar to other short text fields in the menu.

Update 3

Although I attempted the solution proposed by Niket Pathak, the grey overlay persistently hides the lengthy text. A screenshot demonstrating this can be viewed below:

https://i.sstatic.net/6lpcy.png

Answer №1

To achieve this effect, you can utilize a simple combination of CSS and JavaScript. Here's how you can do it:

  1. Create a class called .longtext where you will define the necessary styling.
  2. Select the desired <li> element and apply the above CSS class to its classList to override the default styling like so:

    // var gui = new dat.gui.GUI();
    // ...
    // The following code selects the 4th <li> element with long text.
    gui.__ul.childNodes[4].classList += ' longtext';
    // Similarly, this code targets the 6th <li> element which contains a <div> as its first child with a nested <span>, and adds the class 'full_width'.
    gui.__ul.childNodes[6].childNodes[0].childNodes[0].classList += ' full_width';  
    

Check out the snippet below for a live demonstration:

       var obj = {
           message: 'Hello World',
           displayOutline: false,
           maxSize: 6.0,
           StartingVector: 'Dummy Text',
           SingleLine: '',
           explode: function () {
              alert('Bang!');
           },
       };

      var gui = new dat.gui.GUI();
      gui.remember(obj);
      gui.add(obj, 'message');
      gui.add(obj, 'displayOutline');
      gui.add(obj, 'explode');
      gui.add(obj, 'StartingVector').name('Starting Vector with testing long text like this : ');
      gui.add(obj, 'maxSize').min(-10).max(10).step(0.25);
       gui.add(obj, 'SingleLine').name('A Single long line just for some fun');
      // Apply the 'longtext' class to the correct 'li' element
      gui.__ul.childNodes[4].classList += ' longtext';
      // Traverse through the DOM and add the 'full_width' class to the 'span' element
      gui.__ul.childNodes[6].childNodes[0].childNodes[0].classList += ' full_width';          
    .longtext {
        line-height: 13px !important;
        height: 40px !important;
    }
    .full_width {
        width: 100% !important;
    }
<!DOCTYPE html>
<html lang="en">
<head>
       <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
</head>

<body>

</body>
</html>

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

How can I apply a border to individual table cells in HTML without affecting the entire table?

Struggling to apply a border on table cells, especially when using rowspan. Desiring a table layout with 4 cells - one large cell on the left and three smaller cells on the right side of it. Below is the code snippet I attempted: jsfiddle[dot]net/1fv4dz ...

Can React Native support styling using server-side data?

One of my React Native (RN) components is rendering data from an external server. The data is enclosed within RN components. For example: ... <View> <Text>{this.props.db.greeting}</Text> </View> The 'DB' object is si ...

running a prompt command from my PHP/HTML script

I currently run a puppeteer program by typing c:\myProgram>node index.js in the command prompt. However, I would like to automate this process through my PHP program instead of manually entering it each time. Something similar to this pseudo-code ...

Create a section and a div with a set size in HTML

I'm having trouble setting the height of a div within a section to 100px. Despite my efforts, the height keeps reverting back to 'auto' and adjusts based on the content inside the div. Below is the HTML code: <section id="social" class= ...

Having issues with the background-image style not displaying correctly in the header of an

Trying to update the "background-image:" of a CSS class upon button click. JQuery: $(function() { $('button').on('click', function() { $('.masthead2').css('background-image', 'url("../img/whitehead ...

Is the hook useEffect behaving improperly due to dependency issues?

I'm facing an issue with an infinite loop occurring inside the useEffect hook. I want to trigger a new request only when the id dependency changes. However, when I don't pass data, I encounter problems with updating the state using setData. On th ...

Calculating the median in JavaScript utilizing a for loop

Currently, I am in the process of learning JavaScript. My goal is to calculate the median of a set of numbers that I input through a prompt when I click the button labeled "find median". function CalculateMedia() { var n = prompt("Enter the number of e ...

What could be causing the malfunction in this multi-select code developed by loudev?

I tried adding this link: After following the instructions, the code is still not functioning correctly. I made sure to include jQuery scripts as well because I thought they might be necessary. I'm having trouble identifying where the mistake lies. ...

Steps to retrieve the primary key associated with a duplicate entry error (1062) in MySQL using the Knex.js library

Testing out the database by sending values from an HTML form has been successful so far. Unique inserts and good connections are working well. However, intentionally sending a duplicate username for testing purposes results in an error message - which is e ...

Error message: Upon refreshing the page, the React Router is unable to read properties of

While developing a recipe application using the Edamam recipe API, everything was functioning smoothly until an issue arose when refreshing the Recipe Detail page. The error occurs specifically when trying to refresh the page with a URL like http://localho ...

bulk purchase discount with HTML/JavaScript/PHP

I am looking to add a slider feature to my "Prices" page in order to provide customers with an instant quote based on the quantity they select. The slider should range from 1 to 500 or even up to 1000, but having an input box for customers to enter the qu ...

Creating an IntersectionObserver with the Composition API: A Step-by-Step Guide

I am currently in the process of incorporating an IntersectionOberver that will update the url once the viewport transitions into a new section. I came across This thread and now endeavoring to apply it in vue 3 compositon api. The script is being integra ...

Could you clarify the significance of the brackets in this TypeScript Lambda Expression?

I'm currently delving into an Angular book, but I'm struggling to locate any definitive documentation regarding the usage of square brackets in a lambda expression like [hours, rate]) => this.total = hours * rate. While I grasp that these para ...

mass editing - undesired demands or data bombardment

Lately, I've been extremely frustrated with an issue I've encountered over the past 4 days. When attempting to update multiple items within my store simultaneously, I'm experiencing a strange payload behavior. To elaborate on what I mean by ...

Ways to apply jquery.validate rules that have already been defined to form fields that are added dynamically

I need to duplicate a specific section of a form and apply the same validation rules that were set up before. After researching this issue, I found that most recommendations suggest adding new rules to the newly generated elements. Therefore, I attempted ...

Make necessary changes to empty objects within a JSON array

Modify the null objects in a JSON array. I attempted to use map, but it did not update all the JSON objects. Here is an example of a JSON array: var response = { "code": null, "message": "Total 1 records found", "result": { "ordersList": [ ...

Unable to access a hyperlink, the URL simply disregards any parameters

When I click an a tag in React, it doesn't take me to the specified href. Instead, it removes all parameters in the URL after the "?". For example, if I'm on http://localhost:6006/iframe.html?selectedKind=Survey&selectedStory=...etc, clicking ...

Unable to track user (Mineflayer - Node.js)

Trying to track a player using the mineflayer library in Node.js, but encountering an error within the source code of the library itself. Attempted code: const mineflayer = require('mineflayer'); const { pathfinder, Movements, goals } = require( ...

Arranging DIVs in a vertical layout

Currently, I am working on a design that involves organizing several <DIV> elements in a vertical manner while still maintaining responsiveness. Here are some examples: Wider layout Taller layout I have tried using floats, inline-block display, ...

What is the best way to display single data instance from API using Angular?

My API data is structured in a way that includes various questions and their corresponding options. I am looking to display one question and its alternatives at a time, with the ability to move to the next question upon clicking a "Next" button. Since the ...