We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3232
    • 380 Posts
    I'm trying to get a good understanding of ext.js so that I can build out my manager pages.

    I was able to create multiple tabs on my page without a problem and get a grid setup on one of the tabs. I am trying to create a form on one of my other tabs (which is unrelated to the grid.)

    I was able to create the buttons but none of the fields show up. When I hit the submit button I get a form undefined error in the console.

    I assume I am missing a simple bit but just can't figure it out. I have looked over the documentation at http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.FormPanel and can't seem to figure out what I am missing.

    I would also like to do some javascript pre-processing, if the processing passes I would then like to add a hidden field to the form before it submits. Would this be done with the handler: attribute on the submit button? The processing would be handed off to a third party api and if passed, the hidden field would be a value that the third party returned. Am I allowed to use jQuery in the handler bit as I am much more familiar/comfortable with it?

    widget js:
    SwipeIt.panel.Terminal = function(config) {
        config = config || {};
        Ext.apply(config,{
            id : 'swipeit-panel-terminal'
            ,border: false
            ,baseCls: 'modx-formpanel'
            ,standardSubmit: true
            ,url: SwipeIt.config.connectorUrl
            ,items:[{
                name:'firstName'
                ,fieldLabel:'First Name'
            },{
                name:'lastName'
                ,fieldLabel:'Last Name'
            },{
                name:'email'
                ,fieldLabel:'Email Address'
                ,vtype:'email'
            }]
            ,layout: 'fit'
            ,buttons: [{
                text: 'Submit'
                ,type: 'submit'
                ,handler:  function(){
                    form.submit();
                }
            },{
                text: 'Cancel'
                ,type: 'reset'
            }]
        });
        SwipeIt.panel.Terminal.superclass.constructor.call(this,config);
    };
    Ext.extend(SwipeIt.panel.Terminal,MODx.FormPanel);
    Ext.reg('swipeit-panel-terminal',SwipeIt.panel.Terminal);
      • 33968
      • 863 Posts
      Hey there - I think your fields are not showing up as you haven't defined an 'xtype' for any of them.

      Try adding
      ,xtype: 'textfield'
      

      to each.

      You can attach a handler to the button, something like what you've already done although you won't be able to use jQuery. If you only really need basic validation you can use some of the built in validation such as:
      {
          xtype: 'textfield'
          ,name: 'firstName'
          ,fieldLabel: 'First Name'
          ,allowBlank: 'false'
      }
      
        • 3232
        • 380 Posts
        Thank you Lucas, the missing xtype was the problem. Now I just need to figure out why the form labels are not showing up.

        An example of the validation I need to accomplish is as follows (in jquery.) I'm sure it is possible I will just need to take the time to figure out how to get the value of each field I created.

        Do you happen to have any idea how I can target the form I just created. "form.submit()" doesnt work since I have not given form a value?

        function stripeResponseHandler(status, response) {
                        if (response.error) {
                            // re-enable the submit button
                            $('.submit-button').removeAttr("disabled");
                            // show the errors on the form
                            $(".payment-errors").html(response.error.message);
                        } else {
                            var form$ = $("#payment-form");
                            // token contains id, last4, and card type
                            var token = response['id'];
                            // insert the token into the form so it gets submitted to the server
                            form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
                            // and submit
        		  
        		  var pname = $('#firstname').val();
        		  var camount = "$" + $('#chargeAmount').val() / 100;
        		  if (confirm("Are you sure you want to charge " + pname + " " + camount)) { 
         		      form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
        		      form$.get(0).submit();
        		    }	
                            
                        }
                    }
        
                    $(document).ready(function() {
                        $('.submit-button').css("display", "inline");
        	      	$("#payment-form").submit(function(event) {
                            // disable the submit button to prevent repeated clicks
                            $('.submit-button').attr("disabled", "disabled");
                            var chargeAmount = 0; //amount you want to charge, in cents. 1000 = $10.00, 2000 = $20.00 ...
                            // createToken returns immediately - the supplied callback submits the form if there are no errors
                            Stripe.createToken({
                                number: $('.card-number').val(),
                                cvc: $('.card-cvc').val(),
                                exp_month: $('.card-expiry-month').val(),
                                exp_year: $('.card-expiry-year').val(),
        		        address: $('.address').val(),
        		        zip: $('.zip').val()
                            }, chargeAmount, stripeResponseHandler);
                            return false; // submit from callback
                        });
                    });
          • 3232
          • 380 Posts
          I feel like I am even more confused about creating forms in ExtJs. Is there any time of tutorial or overview on how to create a basic form? I would think this may be useful since a CMP would most likely use one. If someone has an working modx example, it would be extremely helpful so I could get a better understanding.

          I have reviewed the ExtJs documentation but I don't see a correlation between it and Modx's examples (doodles, modextra). Their examples seem totally foreign compared to Modx. I feel like I understand them while I am still trying to figure out the logic in Modx. In my latest code, the fields show up without labels and for form buttons appear outside of the form (which may be correct.)



          SwipeIt.panel.Terminal = function(config) {
              config = config || {};
              Ext.apply(config,{
                  id : 'swipeit-panel-terminal'
                  ,border: false
                  ,baseCls: 'modx-formpanel'
                  ,standardSubmit: true
                  ,url: SwipeIt.config.connectorUrl
                  ,items:[{
                      name: 'firstName'
                      ,fieldLabel: 'First Name'
                      ,labelStyle: 'color:green; font-style:bold; width:130px;'
                      ,xtype: 'textfield'
                  },{
                      name: 'lastName'
                      ,fieldLabel: 'Last Name'
                      ,xtype: 'textfield'
                  },{
                      name:'email'
                      ,fieldLabel: 'Email Address'
                      ,xtype: 'textfield'
                      ,vtype:'email'
                  }]
                  ,buttons: [{
                      text: 'Submit'
                      ,type: 'submit'
                      ,handler:  function(){
                          form.submit();
                      }
                  },{
                      text: 'Cancel'
                      ,type: 'reset'
                  }]
                      // callback handler if submit has been successful
                      ,success:function(form, action){
                          Ext.MessageBox.alert('Success', 'Success');
                      }
          
                  // callback handler if submit has failed
                  ,failure: function(form, action) {
                  Ext.MessageBox.alert('Failure', 'Failure');
              }
              });
              SwipeIt.panel.Terminal.superclass.constructor.call(this,config);
          };
          Ext.extend(SwipeIt.panel.Terminal,MODx.FormPanel);
          Ext.reg('swipeit-panel-terminal',SwipeIt.panel.Terminal);
            • 3232
            • 380 Posts
            So in spending a lot more time with this I think part of the problem is I am not classifying the panel as a form. I have tried layout and xtype but both produce errors. I have read a ton of stuff online and feel like I am getting a pretty good understanding about how ext.js works.

            I guess the biggest thing I am struggling with is extending the classes and modx does. I try using the basic code that I can create and it just errors out.
              • 38925
              • 38 Posts
              For the fieldLabel try to add this right before your items :

              ,layout: 'form'
              ,items: [{...}]