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

yii validation issue #24

Open
venkatesh1229 opened this issue Apr 11, 2018 · 3 comments
Open

yii validation issue #24

venkatesh1229 opened this issue Apr 11, 2018 · 3 comments

Comments

@venkatesh1229
Copy link

venkatesh1229 commented Apr 11, 2018

Hi Drsdre,

how to validate the each form before goes to next from when i click the next button in each case.
i tried to add onclick function in button option, then check has_error like
function myfunction() {
var form = $('#login-form').find('.has-error').length;
if (form == 0) {
return false;
}
}

validation coming but it goes to next form. how to stop that.
Thanks for wizard, Please help.

@aikon2
Copy link

aikon2 commented Aug 12, 2018

is solved?

@InfiniteGH
Copy link

Hello, I replaced .next-step class on Next button to custom class .fake-next-step and created a new function that is called when the user click .fake-next-step It's worked for me

$(document).on("click", ".fake-next-step", function () {
        $(window).scrollTop(0);
        var validated = true;
        var step = $(this).parent().parent().parent().attr('id');
        $search_tag = '#'+step+' input';
        $($search_tag).each(
            function(index){
                var input = $(this);
                if(input.attr('id') !== undefined){
                    $('#w0').yiiActiveForm('validateAttribute', input.attr('id'));
                }
            }
        );
        $search_select_tag = '#'+step+' select';
        $($search_select_tag).each(
            function(index){
                var select = $(this);
                if(select.attr('id') !== undefined){
                    $('#w0').yiiActiveForm('validateAttribute', select.attr('id'));
                }
            }
        );       
        setTimeout(function() {
            var fgroups = $('#'+step).find('.form-group');           
            fgroups.each(function() {
                if ($(this).hasClass("has-error")) {
                    validated = false;
                }
            });
            if(validated) {
                toNextStep();
            }
        }, 200); 
    });
function toNextStep(){
    var $tab_active = $('.wizard .nav-tabs li.active');
    var $next_tab = $tab_active.next();
    var $function = jQuery(this).data('function') || false;

    if ($function){
        var callback = function(){
            $next_tab.removeClass('disabled');
            nextTab($tab_active);
        };
       eval($function);
    } else {
        $next_tab.removeClass('disabled');
        nextTab($tab_active);
    }
}

@gicharu
Copy link

gicharu commented Sep 24, 2019

A clever way of having the validation done on each step is to hide the default buttons. My assumption is that you have split your form into different forms for each step
Like this:
'buttons' => [ 'next' => [ 'options' => [ 'class' => 'hidden', ], ], 'prev' => [ 'options' => [ 'class' => 'hidden', ], ], ],
Then add your own submit buttons like this
<ul class="list-inline pull-right"> <li><?= Html::button('Previous', [ 'class' => 'pull-right btn btn-default prev-step' ]); ?>
</li><li<?= Html::submitButton('Save & Continue', [ 'class' => 'pull-right btn btn-primary' ]); ?>
</li>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants