Clear popup form
  • I have a popup form and i want to clear the form when a user clicks on Add button from the popup.
    I have these functions:
    function initDialog() {
        var myId = this.id;
        var $dlog = $(this),
            opts = { buttons: { "OK": hideDialog, "Add": addComponentInDialog} };

        datepick($dlog);

        $dlog.before("<a class='satellite-content' href='#{id}' onclick=\"showDialog('{id}'); return false;\">Details</a>".replace(/\{id\}/g, myId));
        $dlog.dialog(opts);
    }

    function addComponentInDialog() {
        return addComponent2( $(this) );
    }
    function addComponent2($container) {
        // TODO: Put an error check in here to make sure $container has children


        var $ctx = $container.find("[class]:first-child").eq(0).clone(), // Performance implications w/ this selector? Perhaps ":first-child[class]"?
            re = /([^_]+)\[(\d+)\]/g, // Finds all "array" names in the ID string, with their indexes
            segment = $ctx.attr("id").match(re);
        if (!$.isArray(segment) || segment.length < 1) return// Error check; matching failed
        segment = segment.pop(); // Get the last array name & index
        var i = $container.children("[class]").size(), // 1 + parseInt(segment.match(/\d+/)[0]), // guaranteed b/c of earlier regexp
            repl = segment.replace(/\d+/, i);

        segment = new RegExp("(\\$|_)" + escapeBrackets(segment), "g");
        repl = "$1" + repl;

        $ctx.attr("id", $ctx.attr("id").replace(segment, repl));
        $ctx.html($ctx.html().replace(segment, repl));
        var name = $ctx.attr("name");
        if (!!name)
            $ctx.attr("name", name.replace(segment, repl));

            
        cleanFormFields($ctx);
        datepick($ctx);
        cbMultiples($ctx);

        $($container).prepend("<br />").prepend($ctx);

        return $ctx;
    }
    function cleanFormFields($context) {

        if (!!$context)
           $context.find(":input:not(.remember):not(:button)").val("");
            //$(this).find(":input:not(.remember):not(:button)").val("");
     
    }
    But when i click on Add from the popup nothing happen.How do i fix this issue?
    I think clearFormFields function is not working


    C1.PNG
    390 x 389 - 12K
  • 1 Comment sorted by
  • give one name class to all text boxes which you want to clear like (class='orderLine').
    now bind the click method on add button like this it works :)
    $(function() {
    $('.addbutton').click(function() {
    $('.orderLine input[type="text"]').val('');
    });
    });
    //OR
    just put this line in cleanFormFields function 
    $('.orderLine input[type="text"]').val('');

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Optimum Creative