Reset form behaviour #10

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

Projects

None yet

1 participant

@SandrineProusteau

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