[OPEN] [#1875] Data binding weird issue

  1. #1

    [OPEN] [#1875] Data binding weird issue

    I have the weird issue when working with data binding as in the attached image. the error message: Can not read properties of null (reading 'id')
    Click image for larger version. 

Name:	ext-js-template-issue.jpg 
Views:	79 
Size:	86.4 KB 
ID:	25585

    this issue occur sometimes when the user refresh the binding in my form, below is my code for reproduce the issue:
    @{
        ViewBag.Title = "Ext.net - ui form";
        var X = Html.X();
    }
    
    @(
        X.FormPanel()
            .ID("frmEdit")
            .Title("UI form")
            .Width(1000)
            .Height(250)
            .BodyPadding(5)
            .Layout(LayoutType.Column)
            .Items(
                X.FieldSet()
                    .ColumnWidth(0.4)
                    .MarginSpec("0 0 0 10")
                    .Border(false)
                    .Items(
                        X.DisplayField().ID("pnlImg").ViewModel(new
                        {
                            data = new
                            {
                                thumbnailImgUrl = ""
                            }
                        }).Bind(a => a.Add(new Parameter("html", "<a href='{thumbnailImgUrl}'><img style='max-width: 100%; max-height: 100%;' src='{thumbnailImgUrl}'></a>")))
                    )
            )
            .Buttons(
                X.Button().Text("Set photo").OnClientClick("setImage()"),
                X.Button().Text("Mass set photo").OnClientClick("massiveTest()")
            )
    )
    
    <script>
        var imgIndex = 1;
        var setImage = function () {
            App.pnlImg.getViewModel().set('thumbnailImgUrl', '/img/landscape-0' + imgIndex + '.jpg');
    
            imgIndex++;
            if (imgIndex > 4) imgIndex = 1;
        };
    
        var massiveTest = function () {        
            setTimeout(function () {
                console.log('set photo massively');
                App.pnlImg.getViewModel().set('thumbnailImgUrl', '/img/landscape-0' + imgIndex + '.jpg');
    
                imgIndex++;
                if (imgIndex > 4) imgIndex = 1;
    
                massiveTest();
            }, 200);
        }
    </script>
    As you can see in the image, the massiveTest function run and refresh the data binding every 200 ms, it run for more than 100 times and the issue occur, but sometimes my end-user got this issue even on the first time they refresh the data binding.

    What should I do to clear this issue ?

    Thanks in advance.
    Last edited by fabricio.murta; Sep 17, 2022 at 8:46 PM.
  2. #2
    Hello @user2022!

    Thanks for the test case, that was a tricky one!

    In your test case, change line 20, where it reads X.DisplayField(), use X.Component() instead.

    This should get rid of the issue. Would that simpler component be enough to fulfill your usage scenario? It looks like there's an issue with the DisplayField where garbage collection incorrectly destroys resources pertaining the component, which leads to the errors you described. Simply switching to another component that doesn't employ the affected features, or a component that correctly wraps ups them, is enough to avoid the crash.

    We have logged the issue as #1875 in our bug tracker and will post an update here as soon as we get the issue fixed.

    Let us know if you need some specific feature the DisplayField() would allow you to and we'll see what needs to be done to get the component going without further do.

    If you don't really need anything from the component, you'll be benefitting from a little "lighter" experience, as the bare X.Compoent() will carry on less payload to the page.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello @fabricio.murta,

    Using the Component class works perfectly for my needs, thanks a lot for your help.
    Please close this thread.
  4. #4
    Hello again, @user2022!

    Glad we could help you find a solution that was both lighter in browser load and usable for your usage patterns!..

    We'll keep this open so that we can track and post an update as soon as we get the fix to the DisplayField component ready.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 6
    Last Post: Jun 24, 2020, 10:43 PM
  2. Replies: 3
    Last Post: Jun 25, 2016, 6:34 AM
  3. Replies: 3
    Last Post: Jun 15, 2015, 1:21 PM
  4. Replies: 5
    Last Post: May 16, 2013, 5:39 PM
  5. [CLOSED] Weird date formatting issue
    By mattwoberts in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 25, 2011, 1:07 PM

Posting Permissions