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

ajax validation #2

Open
srakl opened this issue May 25, 2023 · 0 comments
Open

ajax validation #2

srakl opened this issue May 25, 2023 · 0 comments

Comments

@srakl
Copy link

srakl commented May 25, 2023

When doing an ajax validation, i submit an empty form and the input shows an error. with class invalid like this

class=form-control form-control-lg is-invalid"

when i put a valid integter. it changes to

class=form-control form-control-lg is-valid"

then when i enter an invalid integer again, it doesn't change to is-invalid. It works fine before i used this plugin. Any idea why?

here is my javascript submit

<script>
            $(document).ready(function () {  
                var $form = $("#<?= $model->formName() ?>");
                $form.on("submit", function (event, messages) {
                    event.preventDefault();
                    $.ajax({
                        "type":"POST",
                        "url":$form.attr('action'),
                        "data":$form.serialize(),
                        "dataType":"json",
                        "cache": true, 
                        "success":function(data){
                            $("#tax").html(data.rtax);	
                        },     
                        "statusCode": {
                            429: function() {
                                alert("Exceeded request limit.");
                            }
                        }                          
                    });
                    return false;		
                });
            });
            </script>

my form

<?php 
                
                $form = ActiveForm::begin([
                    'id' => $model->formName(),
                    'enableAjaxValidation' => true,
                    'enableClientValidation'=> false,
                    'validateOnBlur' => false,
                    'validateOnChange' => false,
                    'options' => ['autocomplete' => 'off'],
                ]);
 ?>

<?= $form->field($model,'bla',
                ['template' => '
                {label}
                <div class="input-group mb-3">
                    {input}
                    <div class="input-group-append">
                        <span class="input-group-text">%</span>
                    </div>
                    {error}
                </div>
                {hint}
            '])->textInput(['class' => 'form-control form-control-lg']); ?>

<?php echo $form->field($model, 'reCaptcha')->widget(\kekaadrenalin\recaptcha3\ReCaptchaWidget::class) ?>

<?= Html::submitButton(Module::t('app', 'Calculate'), array('buttonType'=>'submit', 'class' => 'btn btn-lg btn-success btn-block shadow-sm')); ?>

<?php ActiveForm::end(); ?>

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

1 participant