简体   繁体   中英

formvalidation.io check isvalid javascript

I have 2 inputs and upon clicking the button I want to check if 1 input is really validated or not (this is to bypass all the validation to check only 1)

I can revalidate it, but I want some boolean feedback if it is validated. something similar to ' var isValidStep = fv.isValidContainer($tab); '

Thanks.

    <div class="col-xs-12 col-md-6 col-lg-4">
            <div class="form-group btn-group-bottom">
            <label for="fFname" class="child">First Name</label>
            <input name="legalFirstName" class="form-control req" id="fFname" autocomplete="off" type="text" />
            </div>
    </div>

    <div class="col-xs-12 col-md-6 col-lg-4">
            <div class="form-group btn-group-bottom">
            <label for="fLname" class="child">Last Name</label>
            <input name="legalLastName" class="form-control req" autocomplete="off" id="fLname" type="text" />
    </div>

    <button type="button" value="Submit" class="btn btn-success easing-effect btn-padding btn-submit subbutton" name="submit" id="subbutton">Submit</button>

    <script>

    $('.rootwizard').formValidation({

            framework: 'bootstrap',
            excluded: ':disabled',
            live: 'enabled',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },

            // Name Validation
            locale: 'en',
            fields: {

                legalFirstName: {
                    live: 'enabled',
                    trigger: 'blur',
                    validators: {
                        stringLengthName: {
                            max: 30,

                        },
                        notEmptyName: {},
                        regexpName: {
                            regexpName: /^[a-zA-Z][a-z\sA-Z0-9.,$;]*$/,

                        }
                    }
                },
                legalLastName: {
                    live: 'enabled',
                    trigger: 'blur',
                    validators: {
                        stringLengthName: {
                            max: 30,

                },
                notEmptyName: {},
                regexpName: {
                            regexpName: /^[a-zA-Z][a-z\sA-Z0-9.,$;]*$/,

                        }
                    }
                }
       }
    });

    $('.btn-submit').click(function() {
      $('.rootwizard').formValidation('revalidateField', 'legalFirstName');
    });

add 'form' tag to your html and change type button to 'submit' like this :

<form class="rootwizard">
<div class="col-xs-12 col-md-6 col-lg-4">
        <div class="form-group btn-group-bottom">
        <label for="fFname" class="child">First Name</label>
        <input name="legalFirstName" class="form-control req" id="fFname" autocomplete="off" type="text" />
        </div>
</div>

<div class="col-xs-12 col-md-6 col-lg-4">
        <div class="form-group btn-group-bottom">
        <label for="fLname" class="child">Last Name</label>
        <input name="legalLastName" class="form-control req" autocomplete="off" id="fLname" type="text" />
</div>

<button type="submit" value="Submit" class="btn btn-success easing-effect btn-padding btn-submit subbutton" name="submit" id="subbutton">Submit</button>
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM