Problem with UI spinner decimal places and event
I'm using a numeric Jquery UI spinner on a text input.
I need the spinner step to be 0.1, but the value to be rounded to 2 decimal places, not 1. If a value like 1.55 is input into the spinner, the value should be set to 1.65 when spun up, not 1.7 like it normally does.
It looks like this is not supported, but I can't find an applicable workaround. I tried a way below, but it doesn't work and also gives an error, 'member not found'.
Also, I need to have an onblur event on the input field, but this should only run when you click in and out of the text box, I can't find a way to make it not run when the spinner buttons are pressed.
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>jQuery UI Spinner - Decimal</title>
- <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
- <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
- <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
- <link rel="stylesheet" href="/resources/demos/style.css">
- <script>
- $(function() {
-
- $( "#TextBox" ).spinner({
- step: 0.10,
- min: 0.0,
- numberFormat: "n",
- incremental: false,
-
- spin: function( event, ui ) {
- if (ui.value > $(this).spinner( "value")) {
- if (ui.value != $(this).spinner( "value") + 0.10) {
- event.preventDefault();
- $(this).spinner( "value" , $(this).spinner( "value") + 0.10);
- }
- }
- }
- });
-
- });
-
- function runOnBlur( ){
- //
- }
- </script>
- </head>
- <body>
-
- <input type="text" id="TextBox" onblur = "runOnBlur()" />
-
- </body>
- </html>