javascript - html input number, min + step, make step ignore min? -


is possible make step ignore min attribute?

<input type="number" min="2" step="5"/> 

as now, steps so: 2, 7, 12, 17, ...
instead, i'd be: 2, 5, 10, 15, 20, ...

my real code uses dynamic values so:

<input type="number" [min]="somevalue" [step]="somestep"/> 

one way solve maybe create directive substitute either min or step same thing without taking consideration other attribute.

so there easy way this? thank you!

the step takes account value of min , max attributes. default browser behaviour , don't think idea try , circumvent this.

i add data-min attribute value of 2 , set min 0. possible check if value of input less custom min value , alter value when needed.

because minimum value 0 means browser follow desired sequence of 0, 5, 10, 15, etc.

const    inputelement = document.getelementbyid('input');      function onvaluechanged(event) {    const       custommin = parseint(inputelement.getattribute('data-min'), 10),      value = parseint(inputelement.value);          if (value > custommin) {      return;    }        inputelement.value = custommin;  }    inputelement.addeventlistener('change', onvaluechanged);
<input id="input" type="number" min="0" step="5" data-min="2" value="2"/>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -