victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
971 stars 475 forks source link

Reset function #433

Open ErickRdz opened 8 years ago

ErickRdz commented 8 years ago

Hi there. I tried to clear error/success messages using the reset function but it didn´t work for me. I´m using the plugin version 2.2.188 and my code is the next:

$("#btn_new_shipping_address").click(function(){ $("#new-shipping-address-form")[0].reset(); });

It cleans my input values but doesn´t the messages created by the validator.

Any advice or comments? Thank you

victorjonsson commented 8 years ago

I would appreciate if you could paste the entire markup of the form.

ErickRdz commented 8 years ago

Sure Victor, this is the markup.

<form class="form-horizontal" role="form" id="new-shipping-address-form">
    <div class="modal-body">
        <div class="form-group has-feedback">
            <div class="col-sm-8 col-sm-offset-3">
                <label for="inputName" id="messageSignup" class="control-label" style="color:red"></label>
            </div>
        </div>
        <div class="form-group has-feedback">
            <label for="inputName" class="col-sm-3 control-label">Nombre <span class="text-danger small">*</span></label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="nsa_recipient_name" placeholder="Nombre" data-validation="required">
            </div>
        </div>
        <div class="form-group has-feedback">
            <label for="inputName" class="col-sm-3 control-label">Apellidos<span class="text-danger small">*</span></label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="nsa_recipient_last_name" placeholder="Apellidos" data-validation="required">
            </div>
        </div>
        <div class="form-group has-feedback">
            <label for="inputEmail" class="col-sm-3 control-label">Telefono <span class="text-danger small">*</span></label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="nsa_phone_number" placeholder="Telefono" data-validation="required number">
            </div>
            <label for="inputPassword" class="col-sm-2 control-label">Ext. </label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="nsa_extension" placeholder="Ext." data-validation-optional="true" data-validation="number">
            </div>
        </div>                  
        <div class="modal-footer text-center">  
            <button type="button" id="btn-new-address-shipping" class="btn btn-group btn-sm btn-default btn-animated">Guardar dirección <i class="fa fa-check"></i></button>
            <button type="button" class="btn btn-group btn-sm btn-danger btn-animated" data-dismiss="modal">Cancelar<i class="fa fa-remove"></i></button>
        </div>
    </form>
victorjonsson commented 8 years ago

The cancel-button needs to have attribute type="reset"

ErickRdz commented 8 years ago

Hi Victor. I tried your last suggestion to clear error/success validator messages adding the attribute type="reset" but it only clears the data inside the inputs. ¿Another suggestion? Many thanks for your time and attention.

victorjonsson commented 8 years ago

It works just fine http://jsbin.com/motesibaha/edit?html,js,output

I need to see more of your code.

ErickRdz commented 8 years ago

Sure Victor, this is my code:

http://jsbin.com/nibode/edit?html,output

victorjonsson commented 8 years ago

You need to initiate the validation by calling $.validate() if you want the reset button to clear all error dialogs.