Results 1 to 5 of 5

Thread: FieldLabel - LabelAlign can not be changed from TOP to any other

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTGWT-1462 in 3.0 RC.
  1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    45

    Default FieldLabel - LabelAlign can not be changed from TOP to any other

    Hello.

    One can change FieldLabel align from LEFT to TOP, but not from TOP to any other. Also setting label align to RIGHT does not work.

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.sencha.gxt.widget.core.client.button.TextButton;
    import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
    import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
    import com.sencha.gxt.widget.core.client.container.Viewport;
    import com.sencha.gxt.widget.core.client.form.FieldLabel;
    import com.sencha.gxt.widget.core.client.form.TextField;
    import com.sencha.gxt.widget.core.client.form.FormPanel.LabelAlign;
    
    
    public class GxtModule implements EntryPoint {    
    
    
        private boolean labelOnTop;
    
    
        public void onModuleLoad() {        
            final Viewport view = new Viewport();
            final VerticalLayoutContainer vlc = new VerticalLayoutContainer();
            
            final TextField field = new TextField();
            final FieldLabel label = new FieldLabel(field, "Label");
            
            final TextButton b = new TextButton("Swap label");
            
            b.addDomHandler(new ClickHandler() {
                public void onClick(ClickEvent p_event) {                
                    labelOnTop = !labelOnTop;
                    label.setLabelAlign(labelOnTop ? LabelAlign.TOP : LabelAlign.LEFT);                
                }
            }, ClickEvent.getType());
    
    
            vlc.add(label, new VerticalLayoutData(1, -1));
            vlc.add(b, new VerticalLayoutData(1, -1));
            view.add(vlc);
            RootPanel.get().add(view);
        }
    }
    Try to click swap button. It will change label position from LEFT to TOP. If you click it again, it should change it back but it does not. Forcing layout and resizing browser does not help either.

  2. #2
    Ext GWT Premium Member lefke123's Avatar
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    113

    Default

    I have to agree with raivis that this can be annoying. The code (revision 2195) that sets the alignment does call the onUpdateOptions method in FieldLabel:

    Code:
    public void setLabelAlign(LabelAlign labelAlign) {
      options.setLabelAlign(labelAlign);
      appearance.onUpdateOptions(getElement(), options);
    }
    But alas, it doesn't do very much with it in the FieldLabelAppearance implementation... If you look in the code of FieldLabelDefaultAppearance you see that only TOP is considered:
    Code:
    public void onUpdateOptions(XElement parent, FieldLabelOptions options) {
      LabelAlign labelAlign = options.getLabelAlign();
      XElement fieldElement = getChildElementWrapper(parent);
      XElement labelElement = getLabelElement(parent);
    
    
      // Adjust for label content, label separator
      if (options.isHtmlContent()) {
        labelElement.setInnerHTML(options.getContent() + options.getLabelSeparator());
      } else {
        labelElement.setInnerText(options.getContent() + options.getLabelSeparator());
      }
    
    
      // Adjust for label alignment
      if (labelAlign == LabelAlign.TOP) {
        parent.addClassName(style.fieldItemLabelTop());
      } else {
        parent.removeClassName(style.fieldItemLabelTop());
      }
    
    
      // Adjust for label width
      if (labelAlign == LabelAlign.TOP) {
        labelElement.getStyle().setProperty("width", "auto");
        fieldElement.getStyle().setPaddingLeft(0, Unit.PX);
      } else {
        int pad = options.getLabelPad();
        if (pad == 0) pad = 5;
        labelElement.getStyle().setWidth(options.getLabelWidth(), Unit.PX);
        fieldElement.getStyle().setPaddingLeft(options.getLabelWidth() + pad, Unit.PX);
      }
    
    
      // Adjust for label padding
      int fieldElementPadding = labelAlign == LabelAlign.TOP ? 0 : (options.getLabelWidth() + options.getLabelPad());
      fieldElement.getStyle().setPaddingLeft(fieldElementPadding, Unit.PX);
    }
    A workaround would be creating your own FieldLabelAppearance I suppose.
    But I was wondering if we could get an update on this issue? Possibly if it would be included in the next beta or not? It would be great if this was fixed on GXT's end, thanks in advance!
    Last edited by lefke123; 23 Feb 2012 at 12:44 AM. Reason: s/LabelField/FieldLabel

  3. #3
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737

    Default

    Yep, makes sense - a bug has been filed with the team, and we'll make sure to update this thread when a fix is prepared.

  4. #4
    Sencha User darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242

    Default

    This should be fixed in beta 4.

    lefke123 or raivis can you validate? I tested your code and it works as expected.

  5. #5
    Ext GWT Premium Member lefke123's Avatar
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    113

    Default

    Yep, it works as expected now, thanks.

Posting Permissions

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