Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I set my number field as empty? #117

Open
lampego opened this issue Aug 19, 2016 · 7 comments
Open

How can I set my number field as empty? #117

lampego opened this issue Aug 19, 2016 · 7 comments

Comments

@lampego
Copy link

lampego commented Aug 19, 2016

  1. Fill my field as 0. Value was: 0.00
  2. Run this code: $(".myFieldClass").val('');

I got 0.00 instead of "string Empty"

@nickblitz
Copy link

+1

@delopez91
Copy link

1+

@headmo
Copy link

headmo commented Sep 5, 2016

+1, any update? thanks very much!

$(".myFieldClass").number('remove');
remove the plugin and init again? (Tested fail :P)

@sawas
Copy link

sawas commented Oct 29, 2016

My work around is add code below

if (!e) { return ""; }

to the line after
e = (e + "").replace(".", a).replace(new RegExp(l, "g"), "").replace(new RegExp(n, "g"), ".").replace(new RegExp("[^0-9+-Ee.]", "g"), "");

this code will check is value is empty or not return the empty string instead of string that use "0" instead of "".

@esemlabel
Copy link

esemlabel commented Nov 15, 2017

Maybe $.valHooks.text.set in else condition should format number only if value has number in .val() call.

else {
    if ( ! /[0-9]/.test( val ) ) {
        return el.value = val;
    }
    
    var num = $.number( val, data.decimals, data.dec_point, data.thousands_sep );
    return $.isFunction(origHookSet) ? origHookSet(el, num) : el.value = num;
}

2018 Update:
I made a simple solution to set any value if needed with .forceval() instead of .val()

(function ($) {
    
    $.fn.forceval = function ( value ) {
        var hookset = $.valHooks.text.set;
        if ( hookset ) {
            delete $.valHooks.text.set;
        }
        var result = this.each( function () {
            $( this ).val( value );
        } );
        if ( hookset ) {
            $.valHooks.text.set = hookset;
        }
        return result;
    };
    
}( jQuery ));

@coyarzun2013
Copy link

+1 same problem here

@elespumoso
Copy link

  1. change input type to number. $('#input').attr('type', 'number');
  2. set value to ''. $('#input').val('');
  3. change input type to text. $('#input').attr('type', 'text');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants