Hybrid View

  1. #1
    Ext User
    Join Date
    Jun 2008
    Posts
    175
    Vote Rating
    0
    businessman332211 is on a distinguished road

      0  

    Default Destroy Form/Window?

    Destroy Form/Window?


    I have a link..when it's clicked on it activates a function called Add_record. This function creates a new EXTJS window..and puts a new EXTJS form inside that window. What happens is if I open (and then either close, submit, or his the x button) on the window..when I open it back up there are 2 forms. If I close/reopen then there are 3 forms. It opens a new form for each time I open it. Is there a way to completely destroy the form/window from existence when the function closes so a new form i created each time?

  2. #2
    Ext User
    Join Date
    Jul 2007
    Posts
    3,128
    Vote Rating
    1
    devnull is an unknown quantity at this point

      0  

    Default


    I suspect you have a problem with your form/window constructor code; likely you are generating a new form each time instead of checking to see if it already exists, or are failing to destroy it properly when closing the window.
    its hard to say without seing the code...

  3. #3
    Ext User
    Join Date
    Jun 2008
    Posts
    175
    Vote Rating
    0
    businessman332211 is on a distinguished road

      0  

    Default


    The code is...for example the link just has an onclick handler calling the add record function which looks like...
    Code:
    <script type="text/javascript">
    function add_record() {
      var comment_win = new Ext.Window({
       el:'add_record',
       layout:'fit',
       width:500,
       height:300,
       closeAction:'hide',
       plain: true,
       buttons: [{
        text:'Submit',
        handler: function() {
         comment_form.getForm().submit({
          method:'GET',
          waitTitle:'Connecting',
          waitMsg:'Sending data...',
          // Functions that fire (success or failure) when the server responds.
          // The one that executes is determined by the
          // response that comes from login.asp as seen below. The server would
          // actually respond with valid JSON,
          // something like: response.write "{ success: true}" or
          // response.write "{ success: false, errors: { reason: 'Login failed. Try again.' }}"
          // depending on the logic contained within your server script.
          // If a success occurs, the user is notified with an alert messagebox,
          // and when they click "OK", they are redirected to whatever page
          // you define as redirect.
          success:function(){
           comment_win.hide();
          },
          // Failure function, see comment above re: success and failure.
          // You can see here, if login fails, it throws a messagebox
          // at the user telling him / her as much.
          failure:function(form, action){
           comment_form.getForm().reset();
           comment_win.hide();
          }
         });
        }
       },{
        text: 'Close',
        handler: function(){
         comment_win.hide();
        }
       }]
      });
      var comment_form = new Ext.form.FormPanel({
        labelWidth: 75,
        url: '{{$html->url('/admin/users/addnewuser')}}/',
        defaultType: 'textfield',
        defaults: {width: 230},
        items: [
         {
          fieldLabel: 'Login Name',
          name: 'login_name',
          allowBlank: false
         },
         {
          fieldLabel: 'First Name',
          name: 'first_name',
          allowBlank: false
         },
         {
          fieldLabel: 'Last Name',
          name: 'last_name',
          allowBlank: false
         }, new Ext.form.ComboBox ({
          fieldLabel: 'Group',
          name: 'Group',
          store: 
           new Ext.data.SimpleStore({
            fields: ["display_field", "value"],       
            data: [
             {{php}}
              // get groups
              $groups = $this->_tpl_vars['groups'];
              // this holds data
              $temp = '';
              $num = 0;
              // loops through/gets data
              foreach($groups as $k=>$v) {
               $temp .= "['".$v."', '".$num."'],";
               $num++;
              }
              // removes last comma
              $temp = substr($temp, 0, strlen($temp)-1); 
              echo $temp;
             {{/php}}   
            ]
           }),
          mode: 'local',
          displayField: 'display_field',
          valueField: 'value'
         }),new Ext.form.ComboBox ({
          fieldLabel: 'Subarea',
          name: 'Subarea',
          store: 
           new Ext.data.SimpleStore({
            fields: ["display_field2", "value2"],       
            data: [
             {{php}}
              // get groups
              $subarealist = $this->_tpl_vars['subarealist'];
              // this holds data
              $temp = '';
              // loops through/gets data
              $num = 0;
              foreach($subarealist as $k=>$v) {
               $temp .= "['".$v."', '".$num."'],";
               $num++;
              }
              // removes last coma
              $temp = substr($temp, 0, strlen($temp)-1); 
              echo $temp;
             {{/php}}   
            ]
           }),
          mode: 'local',
          displayField: 'display_field2',
          valueField: 'value2'
         }),new Ext.form.ComboBox ({
          fieldLabel: 'ReportTo',
          name: 'ReportTo',
          store: 
           new Ext.data.SimpleStore({
            fields: ["display_field3", "value3"],       
            data: [
             {{php}}
              // get groups
              $reporttolist = $this->_tpl_vars['reporttolist'];
              // this holds data
              $temp = '';
              // loops through/gets data
              $num = 0;
              foreach($reporttolist as $k=>$v) {
               $temp .= "['".$k."', '".$num."'],";
               $num++;
              }
              // removes last coma
              $temp = substr($temp, 0, strlen($temp)-1); 
              echo $temp;
             {{/php}}   
            ]
           }),
          mode: 'local',
          displayField: 'display_field3',
          valueField: 'value3'
         }), {
          fieldLabel: 'City',
          name: 'city',
          allowBlank: false     
         }
        ]
      });
      comment_win.add(comment_form);
      comment_win.show();
      return false;
    }
    </script>
    Any advice?

  4. #4
    Ext User
    Join Date
    Jun 2008
    Posts
    175
    Vote Rating
    0
    businessman332211 is on a distinguished road

      0  

    Default


    Any advice?

  5. #5
    Ext User
    Join Date
    Jul 2007
    Posts
    3,128
    Vote Rating
    1
    devnull is an unknown quantity at this point

      0  

    Default


    so you are calling your add_record function multiple times? the window is set to hide instead of destroy, and you do not check for the existence of the window before (re)creating it. you must do one or the other or you end up creating a new one each time the function is called.

  6. #6
    Ext User
    Join Date
    Sep 2009
    Posts
    34
    Vote Rating
    0
    joe123 is on a distinguished road

      0  

    Cool same problem (window destroy / close)

    same problem (window destroy / close)


    Hi,

    I am experiencing the same problem. I set 'closeAction' : 'destroy'. That
    helps. But even after checking if the window already exists it still keeps
    duplicating the formpanel textfields.

    pseudocode:

    if(!window){
    new Window ({closeAction:'destroy'}).show();

    }


    Any ideas??

    Thanks!