Results 1 to 8 of 8

Thread: is 1 component per database field too specific?

  1. #1
    Sencha User
    Join Date
    Jan 2009
    Posts
    37

    Question is 1 component per database field too specific?

    hello,

    I'm currently working on a new web app and uses ext js for the UI. While working on creating the widgets these past few days, I realized something..

    For every model I have in my app, I want to create a few widgets (Form, Grid, etc.) and I was wondering if I should go as far as creating each individual form's elements as a component and use that component inside the form and other widget.

    For example, maybe I should create a ProjectNameTextField which has all the property set (maxLenght, RegEx validator, customized error messages, etc.) so if the maxLenght changes, I will only have to make the change to the component and it will spread through my web app.

    I thought this would be a good idea, then I asked myself if
    1) I really want to do that for all fields
    2) This will make a hell of a lot of small component, is this even good design?

    So here I am, asking you guys what do you think of this? How are you doing this?

    Thanks

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    This is one of Animals favorite complaints!

    You should not create a custom component if your only goal is to configure an existing component. You only want to create a custom component if you are adding specific behavior. In all other cases a factory method is much simpler, e.g.
    Code:
    getProjectNameField: function(config){
      return new Ext.form.TextField(Ext.apply({
        // default config
      }, config));
    }

  3. #3
    Sencha User
    Join Date
    Jan 2009
    Posts
    37

    Default

    Right,

    That's what I meant, should I create pre-configured object for every single database fields?

  4. #4
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    Im siding with Condor/Animal on this, though you might consider creating a more generic 'NameField' that contained your general constraints for a 'Name' type of field, and just configure it each time for 'ProjectName', 'CompanyName', 'PetName', etc. Not sure how that fits in with your situation. Might be a waste, just depends how often you have this 'type' of field.

  5. #5
    Sencha User
    Join Date
    Jan 2009
    Posts
    37

    Default

    My concern was to make sure to have the same validation rules in the backend and the frontend. I was thinking that if I let the frontend developper work out their validation each time.. that sooner than later, it will be a mess to update the validation rules for a specific fields without having to go through the whole app...

  6. #6
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    You could centralize those types of settings as well...make a config.js or whatever...

    PHP Code:
    Ext.ns('myapp.Config');

    myapp.Config.Constraints.ProjectName = {vtype:'name',maxLength:100}; 
    Then in your code...

    PHP Code:
    var CompanyName Ext.applyIf({fieldLabel:'Company Name',name:'companyName'},myapp.Config.Constraints.ProjectName);
    ...
    items: [CompanyName]
    ... 
    Just a thought.

  7. #7
    Sencha User
    Join Date
    Jan 2009
    Posts
    37

    Default

    Well, I gotta say I like that idea...

    This is exactly why I posted to the forum, knowing someone would have such a great idea
    That way, I could have a file that has all the validation settings.. and People would refer to that file!

    Are there any real world project (probably open-source) that uses extensively ExtJS that I can look at? I mean the example on the site are pretty damn good to learn, but I'd like to see a real world web app using it so I can take a look..?

  8. #8
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    I put together a sample app for JSConf that shows how I generally structure an ExtJS app. Without all of the nice directory structure and such, just one big [email protected]$k file

    http://github.com/VinylFox/JSConf/tree/master/2010/

Similar Threads

  1. How do I disable a specific component
    By Albyx in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 14 Jun 2010, 2:00 PM
  2. Say browser to scroll to a specific Ext.Component?
    By maho2nd in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 14 Jan 2010, 4:26 AM
  3. Convert results from database into TreePanel specific format
    By nish1303 in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 4 Nov 2008, 2:26 PM
  4. Help: get value from the specific field easily
    By tomomi in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 14 Nov 2007, 1:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •