[CLOSED] [1.x] - No effect when change Label.StyleSpec inside a CompositeField

  1. #1

    [CLOSED] [1.x] - No effect when change Label.StyleSpec inside a CompositeField

    Hi, I have following code, and the label's color doesn't changed. Anyway to force update on the label after applying style? Thanks.

    <ext:FormPanel ID="FormPanel_Test" runat="server" LabelAlign="Right" LabelWidth="140" Border="false">
            <Items>
                <ext:CompositeField runat="server" FieldLabel="Trading Group Type">
                    <Items>
                        <ext:ComboBox runat="server" ID="combo1" FieldLabel="Test" SelectOnFocus="true" Width="100" TriggerAction="All" Resizable="true" Editable="false" TypeAhead="true" AllowBlank="false" SelectedIndex="0">
                            <Items>
                                <ext:ListItem Text="A" Value="A" />
                                <ext:ListItem Text="B" Value="B" />
                                <ext:ListItem Text="C" Value="C" />
                            </Items>
                            <Listeners>
                                <Select Handler="if (#{combo1}.getValue() == 'A') { #{label1}.styleSpec = 'color:gray'; } else { #{label1}.styleSpec = 'color:black'; }" />
                            </Listeners>
                        </ext:ComboBox>
                        <ext:Label runat="server" ID="label1" Text="TestLabel" StyleSpec="margin:3px" />
                        <ext:Checkbox runat="server" ID="checkbox1" />
                    </Items>
                </ext:CompositeField>
    </Items>
    </ext:FormPanel>
    Last edited by Daniil; Dec 20, 2012 at 1:24 PM. Reason: [CLOSED]
  2. #2
    Hello!

    Try the following Handler:

    <Select Handler="if (#{combo1}.getValue() == 'A') { #{label1}.el.setStyle('color', 'gray'); } else { #{label1}.el.setStyle('color', 'black'); }" />
  3. #3
    Hi @drkoh,

    Just to clarify. The StyleSpec is a config option. Changing it after rendering doesn't make any sense.
  4. #4
    Hi @drkoh

    You should consider make it by adding and removing class of your label.

    pls try change this :
    if (#{combo1}.getValue() == 'A') { #{label1}.styleSpec = 'color:gray'; } else { #{label1}.styleSpec = 'color:black'; }
    to
    if (#{combo1}.getValue() == 'A') { if(!#{label1}.hasClass('myGray') && !#{label1}.hasClass('myBlack')){ #{label1}.addClass('myGray');}else{#{label1}.replaceClass('myBlack','myGray'); }} else { if(!#{label1}.hasClass('myBlack') && !#{label1}.hasClass('myGray')){#{label1}.addClass('myBlack');}else{ #{label1}.replaceClass('myGray','myBlack');  }}
    and in css:
    .myGray{
       color: gray;
    }
    .myBlack{
       color: black;
    }
    You sould check if
    #{label}
    element doesn't contain class 'myGray'. ofcourse you can managa as well on styles but this way is more maintainable. for example if you will need for some reasons change kolor from gray to green you need to do it only in css and it will be work:) You can think about this solution like an investments for future.

    hope this help:)
    Last edited by ViDom; Dec 20, 2012 at 8:38 AM.
  5. #5
    Thanks @Baidaly for solution (please close thread - works).
    And thanks @Danil for clarification and @ViDom for suggestion.

Similar Threads

  1. [CLOSED] Label in CompositeField issue
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Apr 12, 2012, 5:23 PM
  2. CompositeField StyleSpec issue
    By joao.msdn in forum 1.x Help
    Replies: 0
    Last Post: Jan 07, 2011, 1:07 PM
  3. [CLOSED] Aligning label of textfield in compositefield to left of control
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 20, 2010, 2:27 PM
  4. Replies: 0
    Last Post: Jul 09, 2010, 4:19 PM
  5. [CLOSED] Changing StyleSpec of Label
    By danielg in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 26, 2009, 9:04 AM

Posting Permissions