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

Reset form behaviour #10

Open
SandrineProusteau opened this issue Jan 8, 2014 · 0 comments
Open

Reset form behaviour #10

SandrineProusteau opened this issue Jan 8, 2014 · 0 comments

Comments

@SandrineProusteau
Copy link

Could I suggest you these modifications, in order to use reset button in forms:

    if( $this.attr('type') == 'checkbox') {
        var defaultState = '';
        if( $this.is(':checked') ) {
            $this.parent().addClass(defaultOpt.checkedCls);  
            defaultState = 'checked';
        }
        var item = $this.addClass(defaultOpt.hideCls).wrap(wrapTag);
        item.change(function() {
            console.log("EZMARK checkbox changed");
            if( $(this).is(':checked') ) { 
                $(this).parent().addClass(defaultOpt.checkedCls); 
            }
            else {  
                $(this).parent().removeClass(defaultOpt.checkedCls);    
            }
        });
        if(item.parents("form").find("[type=reset]").length>0){
            item.parents("form").find("[type=reset]").click(function(){
                console.log("EZMARK form reset");
                if(defaultState=='checked'){
                    item.parent().addClass(defaultOpt.checkedCls); 
                }else{
                    item.parent().removeClass(defaultOpt.checkedCls); 
                }
            });
        }
    } 
    else if( $this.attr('type') == 'radio') {
        var defaultState = '';
        if( $this.is(':checked') ) {
            $this.parent().addClass(defaultOpt.selectedCls);    
            defaultState = 'checked';
        } 
        var item = $this.addClass(defaultOpt.hideCls).wrap(wrapTag);
        item.change(function() {
            console.log("EZMARK radio changed");
            // radio button may contain groups! - so check for group
            $('input[name="'+$(this).attr('name')+'"]').each(function() {
                if( $(this).is(':checked') ) { 
                    $(this).parent().addClass(defaultOpt.selectedCls); 
                }
                else {
                    $(this).parent().removeClass(defaultOpt.selectedCls);                       
                }
            });
        });
        if(item.parents("form").find("[type=reset]").length>0){
            item.parents("form").find("[type=reset]").click(function(){
                console.log("EZMARK form reset");
                if(defaultState=='checked'){
                    item.parent().addClass(defaultOpt.selectedCls); 
                }else{
                    item.parent().removeClass(defaultOpt.selectedCls);    
                } 
            });
        }       
    }
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