Results 1 to 6 of 6

Thread: Formula not firing when item doesn't exist

  1. #1
    Sencha Premium Member
    Join Date
    Jan 2013
    Location
    London
    Posts
    84

    Default Formula not firing when item doesn't exist

    Hi All

    ExtJS 6.6 Classic

    I'm trying to create a very simple formula to return a users name. Almost straight out of the manual. However is one of the components doesn't exist the formula doesn't appear to be called;

    Code:
        formulas: {
            users_name function(get) {
                console.log('users_name formula called');
    
    
                var fname 	= get('customerRecord.lname'),
                    lname	= get('customerRecord.lname'),
                    name	= (fname && lname) ? (fname + '  ' + lname) : (fname || lname || '');
    
               return (name);
    if fname and lname both exist, everything works as expected.

    If either do not exist formula doesn't appear to get called. Or is crashing before the console.log line gets out. No errors in the console either.


    Rest of code is a popup form, with fname, lname bound to fields. Whole form is actually loadrecord'd after create.


    Anyone seen this before?

    Thanks
    Mark

  2. #2
    Sencha Premium User
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    628
    Answers
    67

    Default

    Use just get('customerRecord') and read the required fields on your own.

    I know is 5 years later

  3. #3
    Sencha Premium Member
    Join Date
    Jan 2013
    Location
    London
    Posts
    84

    Default

    Hi Bluehipy ... 5 years ... no, it's other date on the post ... 5 days :-)

    My problem is that the function isn't getting called at all if the fields are not yet. It doesnt even get to the console.log

    Mark

  4. #4
    Sencha Premium User
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    628
    Answers
    67

    Default

    Your code is wrong.
    You are reading twice the same field in the record.

    I have tested your case and it works just fine.
    Code:
    Ext.application({
        name : 'Fiddle',
    
    
        launch : function() {
            Ext.define('Fiddle.Component', {
                extend: 'Ext.Component',
                alias: 'widget.fiddlecomponent',
                bind: {
                    html: '{users_name}'
                },
                config: {
                    record: null
                },
                viewModel: {
                    data: {
                        record: null
                        
                    },
                    formulas: {
                        users_name: function(get) {
                               console.log('users_name formula called');
                               var fname 	= get('record.fname'),
                                   lname	= get('record.lname'),
                                   name	= (fname && lname) ? (fname + '  ' + lname) : (fname || lname || '');
    
    
                                return (name);
                        }
                    }
                },
                updateRecord: function (newValue) {
                    this.getViewModel().set('record', newValue);
                }
            });
    
    
            var panel = Ext.create('Ext.panel.Panel', {
                items: [{
                    xtype: 'fiddlecomponent',
                    bind: {
                        record: '{recordA}'
                    }
                }, {
                    xtype: 'fiddlecomponent',
                    bind: {
                        record: '{recordB}'
                    }
                }],
                renderTo: Ext.getBody(),
                title: 'Panel Title',
                viewModel: {
                    data: {
                        recordA: Ext.create('Ext.data.Model', {
                             lname: 'Blue',
                             fname: 'Hipy'                         
                        }),
                        recordB: Ext.create('Ext.data.Model', {
                             fname: 'Hipy'                         
                        })
                    }
                }
            });
        }
    });

  5. #5
    Sencha Premium Member
    Join Date
    Jan 2013
    Location
    London
    Posts
    84

    Default

    Hummm .. sorry I think the duplicated field is a typo introduced by me trying to make a simple example. The original was part of a much bigger program.

    Thanks for your code. I will try and create a fiddle based on that and my code. It's possible there's something else causing the issue.

  6. #6
    Sencha Premium Member
    Join Date
    Jan 2013
    Location
    London
    Posts
    84

    Default

    OK, in an effort to leave some clarity on the thread, here is a fiddle of what I was trying to do;

    https://fiddle.sencha.com/#view/editor&fiddle/2kg1

    What I am seeing is that when you click on a partially populated record (eg dino) the viewmodel formula was not being run and therefore the panel title was not being set.

    However if you predefine all the model fields;

    Code:
       viewModel: {
            data:  {
                    fname: null,
                    lname: null
                }
    }

    ... all seems to work as you would expect!

Similar Threads

  1. Initial ViewModel data not firing formula
    By incutonez in forum Ext 5: Q&A
    Replies: 7
    Last Post: 12 Dec 2015, 3:53 PM
  2. applyToMarkup doesn't exist anymore in ext 4?
    By diablo in forum Ext: Discussion
    Replies: 8
    Last Post: 14 Jun 2011, 5:39 AM
  3. Exist Simple method to update tabpanel item without ajax ?
    By ulysse in forum Sencha Ext JS Q&A
    Replies: 2
    Last Post: 3 Dec 2008, 8:07 AM
  4. Replies: 1
    Last Post: 7 May 2008, 10:22 PM
  5. Create item if it doesnt exist already
    By fwabbly in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 13 Dec 2007, 6:21 AM

Tags for this Thread

Posting Permissions

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