locked
second time the empty form is not validating the fields. RRS feed

  • Question

  • User-240513752 posted

    I am opening a modal in div

    <div class="col-lg-2 col-sm-4 col-md-2 col-xs-12">
                        <div class="margin-50"></div>
                        <div id="ContactUs"></div>
                        <a class="center-block btn btn-primary btn-lg contactus" id="btnContactUs" href="javascript:void(0);">Contact Us</a>
                    </div>

    <script type="text/javascript">
        $('.contactus').click(function () {
            $('#contact_us').removeClass('hidden');
             $('#contact_us').dialog({
                modal: true,
                width: 1250,
                
                 title:"Contact Us"
            });
        });


     
    </script>

    here is the partial view form submission button

                    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
                        <br />
                        <input type="submit" class="btn btn-dark  pull-left" id="btncontact" value="Submit Enquiry">
                    </div>
                </div>

    here is a validation script

    <script type="text/javascript">
        var isValidPropertyLocation = false;
        $(document).ready(function () {
    
            $('#DynamicContactUsModel_ContactUs_Phone').mask('(999) 999-9999');
            $('#DynamicContactUsModel_ContactUs_Phone').keyup(function () {
                var $frm = $('#dynamiccontactus');
                $frm.data('formValidation').revalidateField($(this));
    
            });
            ValidateAjaxform();
            $('#ContactUsForm').submit(ProceedContactUsRequest);
    
    
        });
    
    
        function ProceedContactUsRequest() {
            var $form = $("#ContactUsForm");
            var url = "/Dynamic/Index";
            var dataToServer = $form.serialize();
            var $dlg = $form.closest('#dlg_Sub');
    
            if (!$form.data('formValidation').isValid())
            {
                alert(2222);
                e.preventDefault();
            }
    
            $.post(url, dataToServer, function (dataFromServer) {
                NotificationMessage({ Status: 2, Message: ["Record no more exists."] });
                var successid = @AjaxStatus.Success.ToInt();
                alert('dataFromServer.Status=' + dataFromServer.Status + 'Success id= '+successid);
    
                if (dataFromServer.Status == successid)
                {
                    alert(22);
                    $('#contact_us').dialog('close');
                    $('#ContactUsForm')[0].reset();
                }
                else{
                    alert('dataFromServer.Status='+dataFromServer.Status+'errorid='+errorid);
                    return;
                }
            });
            return false;
        }
    
    
    </script>

    the issue is that after the submission of data ,, on second time the empty form is not validating the fields.

    Thursday, May 19, 2016 12:46 PM

All replies

  • User-1780421697 posted

    use validation function

    ValidateAjaxform();

     inside form submission event 

    ProceedContactUsRequest

    document.ready function runs once you have to manage validation inside form submit event, so that every time when you submit form validation is performed.

    Thursday, May 19, 2016 4:40 PM
  • User-240513752 posted

    use validation function

    ValidateAjaxform();

     inside form submission event 

    ProceedContactUsRequest

    document.ready function runs once you have to manage validation inside form submit event, so that every time when you submit form validation is performed.

    not working still

    Friday, May 20, 2016 5:24 AM
  • User61956409 posted

    Hi khan_1,

    Could you share us a sample with all relevant code? then we will reproduce the issue based on your sample code.

    Best Regards,

    Fei Han

    Tuesday, May 31, 2016 9:18 AM