Is there a way to retain the SVG image while also including an input button?

Struggling to hide input buttons with plus and minus SVG images? Different ids tried but no luck. Text box value also getting cut off. How to fix? Snippet provided below with some styling adjustments.

$('.btn-number').click(function(e){
    e.preventDefault();

    fieldName = $(this).attr('data-field');
    type      = $(this).attr('data-type');
    var input = $("input[name='"+fieldName+"']");
    var currentVal = parseInt(input.val());
    if (!isNaN(currentVal)) {
        if(type == 'minus') {

            if(currentVal > input.attr('min')) {
                input.val(currentVal - 1).change();
            }
            if(parseInt(input.val()) == input.attr('min')) {
                $(this).attr('disabled', true);
            }

        } else if(type == 'plus') {

            if(currentVal < input.attr('max')) {
                input.val(currentVal + 1).change();
            }
            if(parseInt(input.val()) == input.attr('max')) {
                $(this).attr('disabled', true);
            }

        }
    } else {
        input.val(0);
    }
});
$('.input-number').focusin(function(){
   $(this).data('oldValue', $(this).val());
});
$('.input-number').change(function() {

    minValue =  parseInt($(this).attr('min'));
    maxValue =  parseInt($(this).attr('max'));
    valueCurrent = parseInt($(this).val());

    name = $(this).attr('name');
    if(valueCurrent >= minValue) {
        $(".btn-number[data-type='minus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the minimum value was reached');
        $(this).val($(this).data('oldValue'));
    }
    if(valueCurrent <= maxValue) {
        $(".btn-number[data-type='plus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the maximum value was reached');
        $(this).val($(this).data('oldValue'));
    }


});
$(".input-number").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) ||
             // Allow: home, end, left, right
            (e.keyCode >= 35 && e.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });
/* https://bootsnipp.com/snippets/dGWP */
.center{
width: 150px;
  margin: 40px auto;

}
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CodePen - Bootstrap Add Plus Minus Button To Input Number</title>
  <link rel='stylesheet' href='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css'><link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<div class="center">
    <div class="input-group">
          <span class="input-group-btn">
              <button type="button" class="btn btn-default btn-number" disabled="disabled" data-type="minus" data-field="quant[1]">
                  <span class="glyphicon glyphicon-minus"></span>
              </button>
          </span>
          <input type="text" name="quant[1]" class="form-control input-number" value="8" min="8" max="30">
          <span class="input-group-btn">
              <button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant[1]">
                  <span class="glyphicon glyphicon-plus"></span>
              </button>
          </span>
      </div>

</div>
<!-- partial -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script  src="./script.js"></script>
<script src='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js'></script>

</body>
</html>

Answer №1

If you want to get rid of the box when the button is pressed, simply add button:focus {outline:0;}:

button:focus {
  outline: 0 !important;
}
.center {
  width: 150px;
  margin: 40px auto;
}
<link rel='stylesheet' href='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css'>

<div class="center">
  <div class="input-group">
    <span class="input-group-btn">
      <button type="button" class="btn btn-default btn-number" data-type="minus" data-field="quant[1]">
        <span class="glyphicon glyphicon-minus"></span>
      </button>
    </span>
    <input type="text" name="quant[1]" class="form-control input-number" value="8" min="8" max="30">
    <span class="input-group-btn">
      <button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant[1]">
        <span class="glyphicon glyphicon-plus"></span>
      </button>
    </span>
  </div>
</div>

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 method to make changes to files on a deployed Angular application without the need to rebuild?

After deploying my Angular application on a production environment using the command npm run build --prod --base -href, I now need to make changes to some static HTML and TypeScript files. However, since the app is already bundled and deployed, I'm un ...

What is the method for determining if a point lies between two others?

I created a small function that seems to have a glitch... function determineIfPointIsBetweenTwoOtherPoints (pointA, pointB, pointToCheck) { var vectorAB = new THREE.Vector3(); vectorAB.subVectors(pointA, pointB).normalize(); var vectorBA = ne ...

The console is still showing an error even though I have updated the record

After updating the existing records in MongoDB, I noticed that the changes are reflected correctly. However, I am still encountering some warnings and errors in the console: {"name":"Bruce","number":"22222","dat ...

Whenever a click event is triggered, the Vue method is executed twice

Why is the set method being executed twice? Check the console when you click the star. Removing @click="set(rating)" results in no action, indicating it is not called elsewhere. http://jsfiddle.net/q22tqoLu/ HTML <div id="star-app" v-cloak> ...

Tips on positioning div elements

I have successfully created a script that shows the preview of an uploaded image on the client-side along with the option to remove it. However, I am facing an issue with the UI design as the position of the close icon is not aligned to the top-right corn ...

CSS - Height not working properly on mobile device model iPhone 6

I've been working on a seemingly simple problem for some time now without success! The issue involves a <header> element with a height of 100px. When the screen size reaches a certain breakpoint (specifically targeting mobile devices), I need ...

What is the method for adding a before pseudo-element to my button element?

HTML & CSS Issue <button>Get Postion</button> Below is the CSS code for styling a button: button { padding: 1rem; background-color: red; color: wheat; border: 4px solid yellowgreen; position: relative; cursor: pointer; ...

Issue with alert not appearing after webpage is refreshed or reloaded on Angular v10

I'm currently working on an Angular single page application. When a user clicks a button, the page refreshes and a message is supposed to be displayed. (TYPESCRIPT) import { Component, OnInit, OnDestroy } from '@angular/core'; export class ...

How can you identify duplicate entries using Mongoose?

I am currently working on a create function and encountering some code that closely resembles this: if(req.body.test !== undefined) { if(--req.body.test EXISTS IN test (model)--) { DO STUFF } else { ...

Ways to enhance the standard functionality of a property in a React component?

Hey there! So, I'm working with a table component from ant design and I'm trying to customize what happens when the current page is changed. function DefaultTable<T extends Entity>(props: TableProps<T>): JSX.Element { const { paginati ...

Unable to access hyperlinked text on WordPress sites

For a school project, I am in the process of developing a theme using WordPress to create a blog. This theme is not intended for sharing so all website design aspects are already pre-made. The issue arises when I attempt to access the blog.php file from ...

Top method for creating 12 dynamic product pages using AngularJS with customized routing and templates

As someone who is still relatively new to AngularJS, I am looking for advice on how to properly structure the products section of my application. My main product page will display all 12 products with clickable links to individual product pages. Each indi ...

A guide to displaying the beginning content of an HTML input element programmatically in React, specifically focusing on cases where the text exceeds the width of the input

My input element initially contains the value 'abcdefghijklmnopqrstuvwxyz' I utilized ref to highlight the characters from 'n' to 'z' inputRef.current.setSelectionRange(18, 26); This code snippet results in the following: h ...

Promise has been unfulfilled

Currently adding this button to my application. In the button component, the following code is present: @Input() callback: () => Promise<null>; onClick() { this.spinnerService.show(); this.callback().then(() => { this.spinne ...

Enhance the multi-level structure of a mongoDB schema

This is an example of my model schema { "_id" : ObjectId("59999454bad567268f78dc09"), "chapters" : [ { "_id" : ObjectId("59999454bad567268f78dc0a"), "individualChapters" : [ { "_id" : ObjectId("59999454bad ...

How can the current route name be retrieved in Vue.js, similar to obtaining the 'this' value?

As a newcomer to vueJS, I'm eager to use the template below to kickstart my project and make it compatible with IE11: Link: codepen erickarbe/pen/pLbRqQ The initial code snippet is as follows: computed: { filteredMembers() { return this.members.f ...

Tips for modifying a state array in Vuex

I have the ability to add and remove entries, but I'm struggling with editing. How can I achieve this using VUEJS, VUEX, and JavaScript? For adding entries, I know I should use PUSH, and for removing entries, SPLICE works fine. But what about editing ...

JavaScript encountered an error stating "phone is not defined" due to an uncaught ReferenceError

Whenever I click on the Phone Number, it displays an error message saying that the function is not defined. How can I fix this issue? Thank you in advance! Here's the code snippet: <div class="product-label"> <h4><?php echo $p["Fu ...

What is the best way to execute Jest tests concurrently using the VSCode extension?

Running the Jest tests in band is essential to prevent errors from occurring. However, I am unsure of how to resolve this issue. The tests run smoothly when executed through the command line. ...

Discovering complimentary number sequences amidst intersecting number sequences

I have a specific number of arrays, each containing a set amount of elements. Each element consists of two attributes represented by numbers. { start: x end: y } These start and end numbers define a range, where the start value is always smaller tha ...