1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    4
    Vote Rating
    0
    mrestine is on a distinguished road

      0  

    Default Answered: fieldset setTitle not sticking

    Answered: fieldset setTitle not sticking


    It's a fairly simple issue. I'm working on the localization of my app. I have just about all of it done, except for the stubborn fieldset titles.

    At the same time (before render) that I translate the fieldLabels for the forms inside said feildsets, I do setTitle on the fieldSet. All the fieldLabels get changed without issue, and setTitle does not error out, either. Stepping through with Firebug, I can see that the title was changed in the fieldset object. Then, when the app renders, the fieldset forgets that its title was changed and shows the old title.

    I'd rather not change the l10n implementation if I can avoid it.

    Can anyone help me out here?

  2. I didnt have a time to inspect why setTitle doesnt work in beforerender function. I just simply inspect what does this function do. What I can say now:

    1) fieldset isnt rendered yet
    2) legend container already exists

    Thats why setTitle function does not work. titleCmp is the legend container and update function will update html content of this component.

    Instead of f.items.get(0) you can use f.down('fieldset') to find first fieldset element

  3. #2
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    439
    Vote Rating
    20
    Answers
    7
    Zdeno will become famous soon enough Zdeno will become famous soon enough

      0  

    Default


    I dont have any problem change title after render. Can you post sample code how do you change the title before render? I think there is the problem why you dont see any changes on fieldset title.

  4. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    4
    Vote Rating
    0
    mrestine is on a distinguished road

      0  

    Default


    After render works for me, but if it's possible to use before render, I would prefer it.

    My use case is rather unique. We haven't been good at keeping all the texts in the View layer, so my methods have been pretty bad ...

    I have a localization class that changes values of the passed in class. Here is a sample:

    A view class Foo's onbeforerender:
    Code:
    Utilities.translate(this);
    Utilities:
    Code:
    Utilities.translate = Ext.Function.bind(function(cls){
        if (cls.xtype == "Foo") {        
            cls.down("#fieldsetItemId").setTitle("Translation");
            // the rest is translated similarly ...
        }
    }
    I couldn't put the text in as variables in Architect to be able to more easily dynamically them, so I did it this way. Not all the view classes are available at the same time, so each view has a before render that calls translate(). Texts that aren't in Views are translated using an array also declared in Utilities, but that's besides the point.

  5. #4
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    439
    Vote Rating
    20
    Answers
    7
    Zdeno will become famous soon enough Zdeno will become famous soon enough

      0  

    Default


    Try this
    PHP Code:
    listeners : {
        
    beforerender : function(form) {
            
    form.items.get(0).titleCmp.update('New title');            
        }

    Live example: http://jsfiddle.net/fNjgU/1/

  6. #5
    Sencha User
    Join Date
    Oct 2012
    Posts
    4
    Vote Rating
    0
    mrestine is on a distinguished road

      0  

    Default


    My implementation is slightly different. I needed another .items.get(0) in that statement to get it right. I wound up with the same issue; firebug told me on the next line that the titleCmp was updated, but the original title showed up. Also, I don't understand the difference between that suggestion and the setTitle I mentioned originally. According to the fieldset source, setTitle calls titleCmp.update() ...

    At this point, I'm starting to think that the problem is rooted in my implementation, which would be why your simple example didn't work in my case. It would probably be less of a headache to just use afterrender than to chase this issue around.

    Thanks for your help!

  7. #6
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    439
    Vote Rating
    20
    Answers
    7
    Zdeno will become famous soon enough Zdeno will become famous soon enough

      0  

    Default


    I didnt have a time to inspect why setTitle doesnt work in beforerender function. I just simply inspect what does this function do. What I can say now:

    1) fieldset isnt rendered yet
    2) legend container already exists

    Thats why setTitle function does not work. titleCmp is the legend container and update function will update html content of this component.

    Instead of f.items.get(0) you can use f.down('fieldset') to find first fieldset element

  8. #7
    Sencha User
    Join Date
    Oct 2012
    Posts
    4
    Vote Rating
    0
    mrestine is on a distinguished road

      0  

    Default


    That makes sense to me now, thanks.

Thread Participants: 1

Tags for this Thread