V
V
Valeriy19972015-08-27 11:37:32
JavaScript
Valeriy1997, 2015-08-27 11:37:32

How to change the condition so that the button would be lit not with one character, but with a certain number?

Here is a code example:

$(function(){
    var inputs = $('[data-mask]');
    if( inputs.length == 0 ) return false;  
    inputs.filter(':not(.ready)').each(function(){
        var inp     = $(this);
        var mask    = inp.attr('data-mask');
        inp.mask( mask,{placeholder:"_"} ).addClass('ready');
    });
    $(document)
        .delegate('.js-numeric','keypress',function(e){
            var key = e.which;
            if( key !=8 && key !=0 && ( key < 48 || key > 57 ) ) return false;
        })
        .delegate('[required]','keyup change', function(e){
            var group = $(this).parents('.form-group');
            group.find('.error-block').slideUp('fast',function(){ group.removeClass('error'); });
            required();
        })
        .delegate('[data-mask]','blur',function(){
            required();
        });
    // check required fields
    var required = function(){
        $('form').each(function(){
            var form    = $(this);
            var enable  = true;
            form
                .find('[required]')
                    .filter('input[type="hidden"], input[type="text"], input[type="password"], input[type="email"], textarea, select')
                        .each(function(){
              if( !$(this).val() ) enable = false;
                        }).end().end()
                .find('button,input[type="button"]').filter('[required]').attr('disabled', ( enable ? false : true ) );
        });
    };
     
 });


and here is the whole code : jsfiddle.net/0xL0fctq/2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2015-08-27
@Valeriy1997

jsfiddle.net/0xL0fctq/3
only if this is not the only field in the form, then you need to check that this is it, for example like this:

if( !$(this).val() || (
    $(this).attr('name') == 'phone'
    && $(this).val().replace(/\D/g,'').length < 5
)) enable = false;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question