Skip to content

Reset form behaviour #10

@SandrineProusteau

Description

@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);    
                } 
            });
        }       
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions