I have create a custom view for the name field on the account, i have a custom boolean field isActive. the purpose if to show a little icon next to the name based on the state of the account (active or incative), the name always come with the default value as inactive when i double checked i found that custom fields on account are always undefined in first initialisation, i have to visit the account and go back to list to get the correct result, below my code: i have logged the result of the id - name and my custom field isActive and seems that id and name are loaded on first initialisation but my custom field isActive is undefined.
I am not sure why this happening or if i am missing something here. by the way i have tried with another custom field and same result undefined.
Any help or hints would b appreciated
PHP Code:
define('spotlight:views/account/fields/name',
['views/fields/varchar'], function (Dep) {
return Dep.extend({
setup: function () {
Dep.prototype.setup.call(this);
this.listenTo(this.model, 'change', () => {
if (this.mode === 'list' || this.mode === 'listLink') {
if (this.model.hasChanged('isActive')) {
this.reRender();
}
}
});
},
afterRender: function () {
Dep.prototype.afterRender.call(this);
console.log(this.model.attributes.id); // this print the id
console.log(this.model.attributes.name); // this print the name
console.log(this.model.attributes.isActive); // custom boolean field print undefined
if (this.mode === 'list' || this.mode === 'listLink') {
if (this.model.get('isActive')) {
let isActive = this.model.get('isActive');
let title = this.model.get('isActive') ? 'Active' : 'Inactive';
let $icon =
$('<i>')
.css('margin-left', '2px')
.addClass(isActive ? 'fas fa-check-circle fa-sm text-success'
: 'fas fa-minus-circle fa-sm text-muted')
.attr('title', title);
this.$el.append($icon);
}
}
},
getAttributeList: function () {
return ['name', 'isActive'];
},
});
});
I am not sure why this happening or if i am missing something here. by the way i have tried with another custom field and same result undefined.
Any help or hints would b appreciated
Comment