[CLOSED] Set and Get Attribute and Value to a field

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Set and Get Attribute and Value to a field

    Hi

    I have a NumberField

     
    X.NumberField()
             .ID("txtDiscounta")
             .HideTrigger(true)
             .Name("m")
    I want to set an attribute to this,like

    foo=bar
    and after this I have a script ,where I select fields by name,and loop though with fields

    var fields = Ext.select('*[name=' m ']');
    fields.each(function (field) {
    
    })
    I need the Value for the particular Attribute.for each field.

    Is there property for assign attribute to a field?please give some sample.
    Last edited by Daniil; Sep 03, 2014 at 6:15 PM. Reason: [CLOSED]
  2. #2
    I try

       X.NumberField()
             .ID("txtDiscounta")
             .HideTrigger(true)
             .Name("m")
             .HideLabel(true)
            .EnableKeyEvents(true)
               .Listeners(l =>
             {
                 l.Render.Handler = @"this.getEl().set({
                             foo : 'bar'
                         });";
    
             })
    var fields = Ext.select('*[name=' m ']');
     fields.each(function (field) {
                console.log(field.getAttribute("foo"));
    
    })
    but not working
  3. #3
    Hi @matrixwebtech,

    I think your JavaScript code has a syntax error. If you run it, you should see an error message.
  4. #4
    Yes there are a javascript error,I rectify ,but not working,Its give null

    <script>
        Ext.onReady(function () {
            var fields = Ext.select('*[name= m]');
            fields.each(function (field) {
                console.log(field.getAttribute("foo"));
     
            })
        })
    
    </script>
    @(X.NumberField()
          .ID("txtDiscounta")
          .HideTrigger(true)
          .Name("m")
          .HideLabel(true)
         .EnableKeyEvents(true)
            .Listeners(l =>
          {
              l.Render.Handler = @"this.getEl().set({
                          foo : 'bar'
                      });";
     
          })
          )
  5. #5
    Ext.onReady fires before rendering of the NumberField.

    Another moment that this
    Ext.select('*[name= m]')
    retrieves an input HTML element, but a NumberField's getEl
    this.getEl()
    a table HTML element which is a wrapper from the input element.
  6. #6
    Hi, Danill

    but a NumberField's getEl

    this.getEl()
    a table HTML element which is a wrapper from the input element.
    not understand properly.its very help full for me if you provide some sample.

    Situation : I have 2 fields and I set 2 different value for the attribute ,when change event fires I take fields by name and check there attribute and doing a calculation as per attribute's value. so I write bellow code.can you please tell me ,how to achieve this.

    @using Ext.Net
    @using Ext.Net.MVC
    
    @{
        var X = Html.X();
        Layout = null;
    }
    <script>
        var calculate = function () {
            var fields = Ext.select('*[name= m]');
            fields.each(function (field) {
                console.log(field.getAttribute("calculationtype"));
    
            })
        }
    
    </script>
    @X.ResourceManager()
    
    
    @(X.NumberField()
          .ID("txt1")
          .HideTrigger(true)
          .Name("m")
          .HideLabel(true)
         .EnableKeyEvents(true)
            .Listeners(l =>
          {
              l.Render.Handler = @"this.getEl().set({
                          calculationtype : 'plus'
                      });";
              l.Change.Handler = "calculate()";
     
          })
          )
          @(X.NumberField()
          .ID("txt2")
          .HideTrigger(true)
          .Name("m")
          .HideLabel(true)
         .EnableKeyEvents(true)
            .Listeners(l =>
          {
              l.Render.Handler = @"this.getEl().set({
                          calculationtype : 'minus'
                      });";
              l.Change.Handler = "calculate()";
     
          })
          
          )
  7. #7
    I don't have a sample, but I have a recommendation. If you use NumberFields, it is better to deal with them as with instances of JavaScript classes, not with HTML elements that they render. Is there any reason why you deal with HTML elements directly?
  8. #8
    I have 8-10 number field on a page ,and I have to do mathematical calculation with them. may be there are some tax and addition charge fields and some discount fields .tax fields values add with total and discount fields values subtract from total.thats why I try to add attribute to fields

    calculationtype : 'plus'
    and
      calculationtype : 'minus'
    so that when

    calculate()
    function call and loop through fields ,I can understand which value need to add and which need to subtract .
  9. #9
    I have 8-10 number field on a page ,and I have to do mathematical calculation with them. may be there are some tax and addition charge fields and some discount fields .tax fields values add with total and discount fields values subtract from total.thats why I try to add attribute to fields

    calculationtype : 'plus'
    and
      calculationtype : 'minus'
    so that when

    calculate()
    function call and loop through fields ,I can understand which value need to add and which need to subtract .

    what do you mean by this,
    it is better to deal with them as with instances of JavaScript classes,
    I will found a post http://www.sencha.com/forum/showthre...l=1#post963003
    If I do like this is that working?
    If so can you please let me know the syntax of
    inputAttrTpl
    Last edited by matrixwebtech; Sep 03, 2014 at 4:59 PM.
  10. #10
    You can define any property on a NumberField itself.
    @(X.NumberField()
        .ID("NumberField1")
        .CustomConfig(cc => cc.Add(new { somePropertyName = "some value" }))
    )
    and access it in JavaScript
    App.NumberField1.somePropertyName
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] EmailValidation attribute
    By jpadgett in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 14, 2013, 4:38 PM
  2. ClientConfig Attribute
    By PerfectElement in forum 1.x Help
    Replies: 6
    Last Post: Nov 11, 2011, 5:50 PM
  3. ServerMapping with more attribute
    By Maia in forum 1.x Help
    Replies: 3
    Last Post: Aug 12, 2010, 5:48 PM
  4. [CLOSED] [1.0] Form field name attribute
    By SandorD in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 22, 2010, 8:39 AM
  5. [1.0] layouts attribute
    By [WP]joju in forum 1.x Help
    Replies: 2
    Last Post: Nov 12, 2009, 2:41 AM

Posting Permissions