Results 1 to 6 of 6

Thread: try to set the value of the fieldLabel dynamicaly

  1. #1
    Sencha User
    Join Date
    Jul 2010
    Posts
    304
    Vote Rating
    0
      0  

    Default try to set the value of the fieldLabel dynamicaly

    Hi,
    I try to set the value of the fieldLabel (of a textField) dynamicaly based on an ajax request and it doesn't work

    Here is the code :

    Code:
    var conn = new Ext.data.Connection();
            conn.request({
                url: "<c:url value="/secure/getSubjectRangeNumber.htm"/>",
                method: 'GET',
                params: { centerId: id },
                success: function(response, opts) {
                        var results = Ext.util.JSON.decode(response.responseText);
                        var result = results.records[0].label;
                        var subjectNumber = Ext.getCmp("subjectNumber");
                        subjectNumber.fieldLabel = '<spring:message code="subject.number"/>'+' '+result;
                    }
                },
                failure: function(response, opts) {
                    
                }
            });
    and my Textfield :

    Code:
    {
          id : "subjectNumber",
          xtype : "textfield",
           name : "subjectNumber",
         readOnly: isReadOnly,
          allowBlank: false,
         width : 400,
         helpText: '<spring:message code="subject.number.help"/>'
    },
    I didn't find another way to do it. Thank you in advance for your answers

  2. #2
    Sencha User
    Join Date
    Mar 2008
    Location
    Brazil
    Posts
    76
    Vote Rating
    9
      0  

    Default

    You can use this override to set fieldlabel:

    Code:
    Ext.override(Ext.form.Field, {
      setFieldLabel : function(text) {
        var label = this.getLabelEl();
        if(label){
    			label.update(text);	
    			this.fieldLabel = text;
    		}
      },
      
      setLabelWidth : function(width){
    		var label = this.getLabelEl();
    		if(label){
    			label.setWidth(width);
    		}
      },
      
      getLabelEl : function(){
    		if (this.rendered){
    			var l = this.el.up('.x-form-item', 10, true);
    			if(l){
    				return l.child('.x-form-item-label');
    			}
    		}
    		return null;
      }
      
    });
    and then just call:

    Code:
    subjectNumber.setFieldLabel('myCoolText');

  3. #3
    Sencha User
    Join Date
    Jul 2010
    Posts
    304
    Vote Rating
    0
      0  

    Default

    Hi fabio and thank you for your answer. it works fine

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890
    Vote Rating
    89
      0  

  5. #5
    Sencha User
    Join Date
    Jul 2010
    Posts
    304
    Vote Rating
    0
      0  

    Default

    Hi Animal and Thank you for your answer. I finally used The method that fabio.parra suggested me

  6. #6
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    132
      0  

    Default

    That code is for a pretty old Ext version. As Animal already suggested you can just use 'label' instead of the whole getLabelEl function.

Similar Threads

  1. Set FieldLabel size
    By fspab in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 15 Jun 2009, 4:57 AM
  2. how to set fieldLabel do not auto begin on a new line
    By wicrosoft in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 13 Aug 2008, 11:44 PM
  3. Replies: 2
    Last Post: 16 May 2008, 5:53 AM
  4. How I get and set the fieldLabel and textarea?
    By scarenci in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 18 Oct 2007, 9:03 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
  •