Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7963769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:41:28+00:00 2026-06-04T05:41:28+00:00

I have a case i hadn’t formerly, and really can’t figure it out, what

  • 0

I have a case i hadn’t formerly, and really can’t figure it out, what is the problem. 🙁
I tried to make a controller class for my old, unsettled js code, tried to make it a bit more object oriented (aye, fail for me, but practicing also is the mother of knowledge).
So, here is my code:

A function calls Main function, which handle variables and pops a form, like:

function Main(com,  multiple, grid) {
    if (CheckTableFunctions(arguments) == true)
    {
        var partner = Partner.Factory(com);
        switch(com)
        {
            case "CreatePartners":
            ...
            break;

            case "GetPartners":
            $e = ShowModal(); // <- this makes a form visible
            Communicate(com, partner, function(data) <- ajax req. with callback
                {
                ... // <- manipulate data, fill form, etc.
                });
            Main("EditPartners", multiple, grid); // <- calling Main Editpartners case
            break;

In fact, the GetPartners case is before the EditPartners, but it is just for fill a form. The Edit, and the event binding goes to editpartners, as seems below:

            case "EditPartners":
            $e = GetModal(); // <- THE ERROR
            $e.find("a.submit").click(function(e){
                partner.fx_data.partner.data = getFormData($e)
                Communicate(com, partner, function(data) // <- return the modified values by ajax
                {
                    CloseModal();
                });
            });
        break;

So, when i run the fn GetModal it returns with an empty object, but the function works correctly GetModal = fn(){$e=$(".poppedModal");return $e;} after the Main(EditP) runned. I think it’s more logical or methodical error than anything else. And to tell the true, i called it with callback, which means i used ShowModal(callback) and when it was ready, i called Main(EditP), but did not work also.

Edit:

Sorry, i forgot the main problem (what i think is the main problem). So i don’t have the form exactly i just have a html prototype of it. Prototype, because i always clone it when it needy.

So here is the showmodal fn and i think this makes the modal unreachable:

function ShowModal()
{
    $container = $('#myModal');
    $clone = $container.clone();
    $clone.removeAttr("id").addClass("clonedModal");
    $clone.modal('show');
    return $clone;
}

function ShowModal()
{
    $container = $('#partnerModal');
    document.getElementById('partnerForm').reset();
    $container.modal('show');
    return $container;
}

Thanks for your help.

Répás

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:41:29+00:00Added an answer on June 4, 2026 at 5:41 am

    Several points:

    1. Members within javascript functions are only localised if declared with var. Otherwise they are ‘outer’ members up to and including the global name space. Several of your vars need to be localised. Undeclared vars can result in nasty bugs.
    2. .clone() will indeed create a clone of an DOM fragment but does not automatically inert it back into the DOM. You need to do that with jQuery instructions such as .append(), .prepend(), .before(), .after(). I strongly suspect that a large part of your problem is trying to do .modal() on an uninserted clone.
    3. It’s not clear why the form needs to be cloned each time it is used. This sort of programming is likely to cause memory leaks. It would be cleaner and more normal to reuse a single form. It’s not hard to reset a form to clear out previously entered/selected values.

    EDIT:

    ShowModal with properly localised variable :

    function ShowModal() {
        var $container = $('#partnerModal');
        document.getElementById('partnerForm').reset();
        $container.modal('show');
        return $container;
    }
    

    In fact, if .modal() is written to be chainable, as it should be, then ShowModal() can be simplified to avoid creating any named members, local or otherwise :

    function ShowModal() {
        $('#partnerForm').get(0).reset();
        return $('#partnerModal').modal('show');
    }
    

    Also, please note that, by convention in javascript programming, only constructor functions should be named with an initial Capital. Constructor functions are those designed to be called with new Fn(). (It’s not important here but there has been much discussion on the subject of constructors and some choose to write their code to avoid the use of new).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200
how can i optimized this code? i dont like to have case statement, is
I have case where the class hierarchy is something like this, +---------------+ | UIElement
I have a problem with writing a test case for my app. At first
I can't seem to figure out why I am getting an InvalidCastException running the
Suppose I have: case class SomeModel( id : Pk[Long], description : String ) object
I have a case where i want to submit a form and get the
I have a case sensitive SERVER (SQL_Latin1_General_CP1_CS_AS) but the Database is Case insensitive (SQL_Latin1_General_CP1_CI_AS).
I have a case where I have a linq2sql dbml with 2 table in
I have a case where I need to select a random item, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.