IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Champs input number qui s'incrément tout seul au troisième clique


Sujet :

JavaScript

  1. #1
    Membre confirmé Avatar de zool.bzh
    Homme Profil pro
    peintre industriel
    Inscrit en
    Octobre 2023
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : peintre industriel
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2023
    Messages : 140
    Par défaut Champs input number qui s'incrément tout seul au troisième clique
    Bonjour,
    suite à cette discussion : https://www.developpez.net/forums/d2...umber-memoire/
    je rencontre un autre probleme qui conserne la case <input name="incr" id="incr" style="font-size: 17px" type="number" min="4" max="100" value="<?=$inc_time?>"
    Quand on clique vite trois fois d'affiler l'input il s'incrémente jusqu'au bout
    Voici le panel
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    <script> 
      document.cookie = "slidex = " + screen.width + "; SameSite=Strict";
      document.cookie = "slidey = " + screen.height + "; SameSite=Strict"; 
    </script>
    <!DOCTYPE html>
    <html>
    <head>
        <link href="../css/grid.css" rel="stylesheet" type="text/css" />
        <link href="../css/nbr-tof.css" rel="stylesheet" type="text/css" />
        <link href="../css/range.css" rel="stylesheet" type="text/css" />
        <link href="../css/custom.css" rel="stylesheet" type="text/css" />
        <link href="../css/text.css" rel="stylesheet" type="text/css" />
        <link href="../css/area.css" rel="stylesheet" type="text/css" />
        <link href="../css/custom_nbr.css" rel="stylesheet" type="text/css" />
        <script src="../css/custom_nbr.js"></script>
    </head> 
     
    <body bgcolor= "#FFF">
       <div class="txt-center">
       <spam class="gris6">cliques sur </span><span class="vio">valider</span><span class="gris6"> apres chaque action et </span><span class="vio">reset</span><span class="gris6">  pour remetre a zéro</span>
       </div>
       <div class="block">
            <div style "border 1px solid #CA0000" class="wrapper">
            <div style="width:250px; border: 1px solid #000000" class="one">
            <form method="GET" action="index.php">
    <?php
     
    session_start();
     
    $pdo = new PDO('mysql:host=IP;dbname=Table', 'ID', 'Pass');
     
        if (isset($_GET['dos'])) {
            $dos = $_GET['dos'];
        } else { 
            $dos = "Dossier_1";
        }
     
      
        $sql_count = 'SELECT COUNT(name_tof) AS new_tof FROM demo WHERE dos_tof = :dos_tof';
        $count_less = $pdo->prepare($sql_count); 
        $count_less->execute(array('dos_tof' => $dos)); 
        $count_tof = $count_less->fetch();
        $nbr_tof = $count_tof['new_tof'];
       
        if ($nbr_tof<=50) {
       
            $lot1 = 1;
            $lot3 = $nbr_tof;
            
        } else { 
                    
                    $lot1 = 1; 
            $lot3 = 50;
            
            }
     
        $sql_done = 'SELECT min(height), max(height), min(width), max(width), name_tof, dos_tof FROM demo WHERE dos_tof = :dos_tof';
        $sth_less = $pdo->prepare($sql_done); 
        $sth_less->execute(array('dos_tof' => $dos)); 
        $done_pics = $sth_less->fetch();
        $nbr_tof = $sth_less -> rowCount();
     
            $heightmin = $done_pics['min(height)'];
        $heightmax  = $done_pics['max(height)'];
        $widthmin = $done_pics['min(width)'];
        $widthmax = $done_pics['max(width)'];
     
    if (!isset($_GET['hmin']) && !isset($_GET['hmax']) && !isset($_GET['wmin']) && !isset($_GET['wmax'])) {
        
            $hmin_get = $heightmin;
            $hmax_get = $heightmax;
            $wmin_get = $widthmin;
            $wmax_get = $widthmax;
     
    } else {
            
            $hmin_get = $_GET['hmin'];
            $hmax_get = $_GET['hmax'];
            $wmin_get = $_GET['wmin'];
            $wmax_get = $_GET['wmax'];
     
    }
            if(!isset($_GET['incr']) || $_GET['incr'] == "") {
                    $inc_time = 4;
            } else {        
        $inc_time = $_GET['incr'];
            }
     ?>
    <ul   id="menu-accordeon">
        <li style="width: 250px"><a href="#">Categories</a>
            <ul style="width: 250px; z-index: 1000;">
    <?php
    $dir = 'tofs/';
    $fil_dir = scandir($dir);
    $nbr_dir = count($fil_dir);
    $nbr_dir = $nbr_dir-1;
     
     
     
     for ($t=2; $t<=$nbr_dir; $t++) {
     
            $str = $fil_dir[$t];
            $order = '_';
            $replace = ' ';
     
            $fil_com[$t] = str_replace($order, $replace, $str);
             
                        echo '<li><a href="index.php?dos='.$fil_dir[$t].'&hmax='.$hmax_get.'&hmin='.$hmin_get.'&wmin='.$wmin_get.'&wmax='.$wmax_get.'&incr='.$inc_time.'&pics=De_'.$lot1.'_à_'.$lot3.'">'.$fil_com[$t].'</a></li>';
                                             
            }
                            
                echo '<input id="dos" name="dos" type="hidden" value="'.$dos.'">';
                       
    ?>	 
    	 </ul>
       </li>
    </ul>
     
     
    <?php   
        $dir_pics  = $dos;
        $less = "_";
        $dir_done   = " ";
        $dos_one = str_replace($less, $dir_done, $dos);
         echo '<input type="hidden" name="incr" value="'.$inc_time.'"/>';
            echo '<span class="gris6">dossier : </span><span class="vio">'.$dos_one.'<br></span>'
     
              ?>
    <span class="gris6">durée du diaporama : <br><span style="height: 30px; width: 57px;" class="custom-input-number">
        <input name="incr" id="incr" style="font-size: 17px" type="number" min="4" max="100" value="<?=$inc_time?>">
            <span class="input-number-control">
            <span style="color: #000" data-action="inc"></span>
            <span  style="color: #000" data-action="dec"></span>
            </span> 
        </span>
    </span>
    <?php
                      
     
     
        if (isset($_GET['reset'])) {
       
            $heightmin = $done_pics['min(height)'];
            $heightmax  = $done_pics['max(height)'];
            $widthmin = $done_pics['min(width)'];
            $widthmax = $done_pics['max(width)'];    
            
            }
            
            $mult = ceil($nbr_tof/50)-1;
     
    ?>
     
    </div>
    	<div   class="boxcenter two"> 
     
        	<span class="gris9">hauteur comprise entre
            <input type="range" class="custom-slider custom-slider-bullet" name="hmin" id="hmin"
    	    value="<?php  if (isset($_GET['reset'])) { echo $heightmin; } else { echo $hmin_get; }; ?>"
    	    min="<?php echo $heightmin ?>"
    	    max="<?php echo $heightmax ?>" 
    	    oninput="this.nextElementSibling.textContent = this.value"/>
            <output><?php echo  $hmin_get ?>
    		</output><br>
     
            et<br>
     
    	    <input type="range"  class="custom-slider custom-slider-bullet" name="hmax" id="hmax" 
    	    value="<?php  if (isset($_GET['reset'])) { echo $heightmax; } else { echo $hmax_get; }; ?>"
    	    min="<?php echo $heightmin; ?>"
    	    max="<?php echo $heightmax; ?>" 
    	    oninput="this.nextElementSibling.textContent = this.value"/>
            <output><?php echo $hmax_get  ?>
    	    </output>
            </span>
        </div>
        <div	class="boxcenter three"> 
     
    	    <span class="gris9">largeur comprise entre
            <input type="range"  class="custom-slider custom-slider-bullet" name="wmin"id="wmin" 
    	    value="<?php  if (isset($_GET['reset'])) { echo $widthmin; } else { echo $wmin_get; }; ?>"
    	    min="<?php echo $widthmin  ?>"
    	    max="<?php echo $widthmax ?>"
    	    oninput="this.nextElementSibling.textContent = this.value"/>
            <output><?php echo $wmin_get ?>
    	    </output><br>
     
    	    et<br>
     
    	    <input type="range"  class="custom-slider custom-slider-bullet" name="wmax"id="wmax" 
    	    value="<?php  if (isset($_GET['reset'])) { echo $widthmax; } else { echo $wmax_get; }; ?>"
        	min="<?php echo $widthmin  ?>"
    	    max="<?php echo $widthmax ?>"
        	oninput="this.nextElementSibling.textContent = this.value"/>
            <output><?php echo $wmax_get ?>
    	    </output>  </span>
    <?php
        $sql_calc = 'SELECT height, width, name_tof, dos_tof FROM demo WHERE dos_tof = :dos_tof AND height <= :hmax_get AND height >= :hmin_get AND width >= :wmin_get AND width <= :wmax_get';
        $sth_calc = $pdo->prepare($sql_calc); 
        $sth_calc->execute(array('dos_tof' => $dos,
                                 'hmax_get' => $hmax_get,
                                                         'hmin_get' =>$hmin_get,
                                                          'wmax_get' => $wmax_get,
                                                          'wmin_get' => $wmin_get
                                                )); 
            $done_calc = $sth_calc->fetchAll();
            $nbr_tof = $sth_calc -> rowCount();
     
    ?>
     
            </div>
            <div style="width: 200px" class="boxthree four">
         <input style="width: 90px; height: 30px; font-size: 15px;" type="submit" name="val" value="Valider" />
                 	<?php 
               $mult = ceil($nbr_tof/50)-1;
               if ($mult == 0) { ?>
    		   <input type="hidden" name="pics" value="De_1_à_<?=$nbr_tof?>">
    	   <?php
               } if ($mult >= 1) { ?>
    		   <input type="hidden" name="pics" value="De_<?=$lot1?>_à_<?=$lot3?>">
    	   <?php
               }
               ?> 
    	 	<input style="width: 90px; height: 30px; font-size: 15px;" type="submit" name="reset" value="reset" />
     
     
    <?php
     
        echo "<br><span class='gris9'>".$nbr_tof." photos dans la base</span>";
       $mult = ceil($nbr_tof/50)-1;                 
     
    if ($mult == 0) { 
                    $lot1= 1; 
                    $lot3 = $nbr_tof;
    }
     
     
     
    ?> <ul   id="menu-accordeon">
         <li style="width: 200px;"><span class="vio"><a href="#">De_<?php echo $lot1; ?>_à_<?php echo $lot3; ?></a></span>
      <ul style="width: 200px; z-index: 1000;">
    <?php
    if ($mult==1) {
        $lot1=1;
        $lot3=50;
            echo '<li><a href="index.php?dos='.$dos.'&hmax='.$hmax_get.'&hmin='.$hmin_get.'&wmin='.$wmin_get.'&wmax='.$wmax_get.'&incr='.$inc_time.'&pics=De_'.$lot1.'_à_'.$lot3.'">De_'.$lot1.'_à_'.$lot3.'</a></li>';
        $lot1 = 51;
        $lot3 = $nbr_tof;
            echo '<li><a href="index.php?dos='.$dos.'&hmax='.$hmax_get.'&hmin='.$hmin_get.'&wmin='.$wmin_get.'&wmax='.$wmax_get.'&incr='.$inc_time.'&pics=De_'.$lot1.'_à_'.$lot3.'">De_'.$lot1.'_à_'.$lot3.'</a></li>';
            
    }
     
     
     
    $t="";
    if ($mult>1) {
                    for ($t=1; $t<=$mult; $t++) {
                $lot3 = $t*50;
                $lot1 = $lot3-49;
             
                echo '<li><a href="index.php?dos='.$dos.'&hmax='.$hmax_get.'&hmin='.$hmin_get.'&wmin='.$wmin_get.'&wmax='.$wmax_get.'&incr='.$inc_time.'&pics=De_'.$lot1.'_à_'.$lot3.'">De_'.$lot1.'_à_'.$lot3.'</a></li>';
     
            }
          
            $lot1 = $lot3+1;
        $lot3 = $nbr_tof;
                
            echo '<li><a href="index.php?dos='.$dos.'&hmax='.$hmax_get.'&hmin='.$hmin_get.'&wmin='.$wmin_get.'&wmax='.$wmax_get.'&incr='.$inc_time.'&pics=De_'.$lot1.'_à_'.$lot3.'">De_'.$lot1.'_à_'.$lot3.'</a></li>';
     
    }
     
    ?>
     
      </ul>
    	 </li>
            </ul>
     
    </div>
     
    <div class="five">
     <?php
    $l = 1;
    $m = 1;
     
    global $data;
     
    if ($nbr_tof <= 50) {
      
        $lot1 = 1;
        $lot3 = $nbr_tof;
      
    } else {  
     
        $values = explode("_", $_GET['pics']);
            $lot1 = $values[1];
            $lot3 = $values[3];
     
    }
     
    $l = 1;
    foreach ($done_calc as $done_file) {
     
        $data[$l]['dim']      = array($done_file['height'],  $done_file['width']);
        $data[$l]['dos']      = $dos;
            $data[$l]['name_tof'] = $done_file['name_tof'];
        $data[$l]['lot']      = array($lot1, $lot3);
        $data[$l]['nbr_tof']  = $nbr_tof;
        $data[$l]['selecta']  = $l;
     
            $l++;
     
    }       
            $data[1]['incr']     = $inc_time;
    $_SESSION['data'] = $data;
            
    for($m=$lot1; $m<=$lot3; $m++) {
     
        $name_time = $_SESSION['data'][$m]['name_tof']; 
     
        echo '<span class="ombre"><a href="transmit.php?dos='.$dos.'&hmax='.$hmax_get.'&hmin='.$hmin_get.'&wmin='.$wmin_get.'&wmax='.$wmax_get.'&selecta='.$m.'&pics=De_'.$lot1.'_à_'.$lot3.'&incr='.$inc_time.'&zoom=off#tof"><img src="min/'.$dos.'/'.$name_time.'"/></a></span>';
     
    }
     
    ?>
     
        </div>
       </form>
      </div>
     </body>
    </html>
    le custom input number css
    Code css : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    .custom-input-number {
      position: relative;
      display: inline-flex;
      border-bottom: 1px solid #B300B3;
     
      & input[type="number"] {
        font: inherit;
     
    	border: none;
        outline: none;
      background: #000;
     color: #B300B3;
     }
     
      & input[type="number"] {
        -webkit-appearance: textfield;
        -moz-appearance: textfield;
        appearance: textfield;
      }
     
      & input[type=number]::-webkit-inner-spin-button,
      & input[type=number]::-webkit-outer-spin-button {
        -webkit-appearance: none;
      }
    }
    .input-number-control {
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;
      border-left: 1px solid #666;
      visibility: visible;
      position: absolute;
      width: 100px;
      right: 0;
      bottom: 0;
      top: 0;
     
      & [data-action] {
        width: 100%;
        height: 50%;
        overflow: hidden;
        text-align: center;
        line-height: 1;
        background: #999;
        cursor: pointer;
        user-select: none;
        line-height: .75;
      }
     
      & [data-action]:hover {
        background: #B300B3;
      }
     
      & [data-action]:active {
        background: #999;
        color: #000;
      }
     
      & [data-action]:first-child {
        border-bottom: 1px solid #B300B3;
      }
    }
    .custom-input-number:hover .input-number-control {
      visibility: visible;
    }
     
    [type="number"].default {
      font: inherit;
    color: #999;
    }
    le javascrit :
    Code js : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    "use strict";
    const customInputNumber = function() {
      function incDecNumber(e) {
        const elem = e.target.closest("span[data-action]");
        elem.focus();
     
        const elemNumber = elem.closest(".custom-input-number")
          .firstElementChild;
        elem.onpointerup = () => {
          setTimeout(() => {
            clearInterval(elem._timer);
          });
          elem.onpointerup = null;
          // focus ici pour conserver la position du curseur
          elemNumber.focus();
        }
        elem.setPointerCapture(e.pointerId);
        let action;
        switch (elem.dataset.action) {
          case "inc":
            action = "stepUp";
            break;
          case "dec":
            action = "stepDown";
            break;
          default:
            return;
        }
        elem._timer = setInterval(() => {
          elemNumber[action]();
          elemNumber.dispatchEvent(new Event("input"));
        }, 100)
      }
     
      function initInput() {
        const elemIncDec = document.querySelectorAll("[data-action='inc'], [data-action='dec']");
        elemIncDec.forEach((el) => {
          el.addEventListener("pointerdown", incDecNumber);
          el.style.touchAction = "none";  // for tactile
        });
      }
     
      if (["complete", "interactive"].includes(document.readyState)) {
        initInput();
      }
      else {
        document.addEventListener("DOMContentLoaded", initInput);
      }
    };
    customInputNumber();
    la page : -> oOo
    voila,comment faire pour que la champ ne s'emballe pas ??

  2. #2
    Membre confirmé Avatar de zool.bzh
    Homme Profil pro
    peintre industriel
    Inscrit en
    Octobre 2023
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : peintre industriel
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2023
    Messages : 140
    Par défaut
    prenons le problème a ça source -> Customisation des éléments input de type number. de NoSmocking
    A la base ça bug quand on bourinne vers le haut
    Je crois que je vais me résigner et garder ce bug

  3. #3
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 207
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 207
    Par défaut
    Bonjour,
    corrige le code comme suit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
        elem.onpointerup = () => {
    //      setTimeout(() => {
            clearInterval(elem._timer);
    //      });
          elem.onpointerup = null;
          // focus ici pour conserver la position du curseur
          elemNumber.focus();
        }
    Nota : j'avais bien repéré cet effet indésirable mais même pas corriger

    Dans ton cas un <input type="number"> « classique » serait largement suffisant.

  4. #4
    Membre confirmé Avatar de zool.bzh
    Homme Profil pro
    peintre industriel
    Inscrit en
    Octobre 2023
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : peintre industriel
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2023
    Messages : 140
    Par défaut
    j'y tiens a mon custom !!
    Pour info se garderais le script dans l'état car la correction est moins bien

  5. #5
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 207
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 207
    Par défaut
    j'y tiens a mon custom !!
    c'est toi le patron

    Pour info j'ai apporté un correctif au code, à voir sur le lien Custom input number.

Discussions similaires

  1. Champ qui se rempli tout seul lors de l'envoi formulaire
    Par LhIaScZkTer dans le forum ASP.NET
    Réponses: 2
    Dernier message: 22/07/2008, 18h59
  2. Formulaire qui se valide tout seul :8O:
    Par Boumeur dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 13/04/2005, 12h21
  3. Avoir un champ qui se decremente tout seul
    Par romeo9423 dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 15/02/2005, 04h32
  4. [ContrôleBD] DBCtrlGrid qui se redimensionne tout seul !
    Par LadyWasky dans le forum Composants VCL
    Réponses: 8
    Dernier message: 01/07/2004, 23h08
  5. TCanvas et handle qui se désalloue tout seul
    Par efourmon dans le forum Langage
    Réponses: 3
    Dernier message: 14/01/2004, 11h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo